using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Drawing;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Forms;
using System.Windows.Input;
using System.Windows.Markup;
using Common;
using Common.Enum;
using Common.NotifyEvent;
using Converters;
using device;
using Infragistics.Win;
using Infragistics.Win.CalcEngine;
using Infragistics.Win.Printing;
using Infragistics.Win.SupportDialogs.FilterUIProvider;
using Infragistics.Win.UltraWinDataSource;
using Infragistics.Win.UltraWinGrid;
using MainView.Windows;
using Report;
using SExperiment;
using SExperiment.ExperimentResult;
using SProject.Paramter;
using SSettings;
using SWellPlate;

namespace MainView.MainControls
{
	public partial class UCWellInfo : System.Windows.Controls.UserControl, IDisposable, IComponentConnector
	{
		public const string Key_MidValueTarget = "SampleTargetItem.Result.MidValue";

		public const string Key_MidValueWell = "WellCell.Well.Result.MidValue";

		public const string Key_MidValueSample = "WellCell.Well.Sample.Result.MidValue";

		private const int CellPadding = 2;

		public static readonly RoutedEvent OnSelectionChangedRoutedEvent = EventManager.RegisterRoutedEvent("OnSelectionChangedRoutedEvent", RoutingStrategy.Bubble, typeof(EventHandler<RoutedEventArgs>), typeof(UCWellInfo));

		public static readonly RoutedEvent OnChannelNoChangedRoutedEvent = EventManager.RegisterRoutedEvent("OnChannelNoChangedRoutedEvent", RoutingStrategy.Bubble, typeof(EventHandler<ChannelNoChangedRoutedEventArgs>), typeof(UCWellInfo));

		public static readonly DependencyProperty WellInfoTypeProperty = DependencyProperty.Register("WellInfoType", typeof(EWellInfoType), typeof(UCWellInfo), new UIPropertyMetadata(EWellInfoType.Edit));

		public static readonly DependencyProperty ColorModeProperty = DependencyProperty.Register("ColorMode", typeof(EColorMode), typeof(UCWellInfo), new UIPropertyMetadata(EColorMode.Channel, OnColorModeChanged));

		public static readonly DependencyProperty SubsetProperty = DependencyProperty.Register("Subset", typeof(Subset), typeof(UCWellInfo), new UIPropertyMetadata(null));

		public static readonly DependencyProperty AutoWidthProperty = DependencyProperty.Register("AutoWidth", typeof(bool), typeof(UCWellInfo), new PropertyMetadata(false, OnAutoWidthChanged));

		public static readonly DependencyProperty GridColumnsProperty = DependencyProperty.Register("GridColumns", typeof(GridColumns), typeof(UCWellInfo), new PropertyMetadata(null, OnGridColumnsChanged));

		public static readonly DependencyProperty TargetsProperty = DependencyProperty.Register("Targets", typeof(ObservableCollection<ChartData>), typeof(UCWellInfo), new UIPropertyMetadata(null, OnTargetsChanged));

		public static readonly DependencyProperty HighLightProperty = DependencyProperty.Register("HighLight", typeof(bool), typeof(UCWellInfo), new UIPropertyMetadata(true));

		public static readonly DependencyProperty RowSpaceModeProperty = DependencyProperty.Register("RowSpaceMode", typeof(ERowSpaceMode), typeof(UCWellInfo), new UIPropertyMetadata(ERowSpaceMode.Null, OnRowSpaceModeChanged));

		public static readonly DependencyProperty DataRowSelectModeProperty = DependencyProperty.Register("DataRowSelectMode", typeof(EDataRowSelectMode), typeof(UCWellInfo), new UIPropertyMetadata(EDataRowSelectMode.Target, OnDataRowSelectModeChanged));

		private bool _CustomSort;

		public static readonly DependencyProperty SampleSortModeProperty = DependencyProperty.Register("SampleSortMode", typeof(ESampleSortMode), typeof(UCWellInfo), new PropertyMetadata(ESampleSortMode.Column, OnSampleSortModeChanged));

		public static readonly DependencyProperty TableSizeModeProperty = DependencyProperty.Register("TableSizeMode", typeof(ESizeMode), typeof(UCWellInfo), new UIPropertyMetadata(ESizeMode.Small, OnTableSizeModeChanged));

		public static readonly DependencyProperty UseScientificProperty = DependencyProperty.Register("UseScientific", typeof(bool), typeof(UCWellInfo), new UIPropertyMetadata(true, OnUseScientificChanged));

		public static readonly DependencyProperty ExperimentProperty = DependencyProperty.Register("Experiment", typeof(Experiment), typeof(UCWellInfo), new UIPropertyMetadata(null, OnExperimentChanged));

		protected CollectionViewSource view = new CollectionViewSource();

		private bool[] _ChannelDisplayInit;

		private Hashtable _RegisteredItem = new Hashtable();

		public UltraGrid ultraGrid = new UltraGrid();

		protected UltraDataSource informationTable = new UltraDataSource();

		private Infragistics.Win.Appearance appearanceHighLight = new Infragistics.Win.Appearance();

		private NumberFormatInfo numberFormatInfo;

		private ColumnFilter currentColumnFilter;

		protected bool shouldFilter = true;

		public System.Windows.Controls.ContextMenu Menu = new System.Windows.Controls.ContextMenu();

		private bool _IsMouseDown;

		private ChartData highLightChartData;

		public EWellInfoType WellInfoType
		{
			get
			{
				return (EWellInfoType)GetValue(WellInfoTypeProperty);
			}
			set
			{
				SetValue(WellInfoTypeProperty, value);
			}
		}

		public EColorMode ColorMode
		{
			get
			{
				return (EColorMode)GetValue(ColorModeProperty);
			}
			set
			{
				SetValue(ColorModeProperty, value);
			}
		}

		public Subset Subset
		{
			get
			{
				return (Subset)GetValue(SubsetProperty);
			}
			set
			{
				SetValue(SubsetProperty, value);
			}
		}

		public bool AutoWidth
		{
			get
			{
				return (bool)GetValue(AutoWidthProperty);
			}
			set
			{
				SetValue(AutoWidthProperty, value);
			}
		}

		public GridColumns GridColumns
		{
			get
			{
				return (GridColumns)GetValue(GridColumnsProperty);
			}
			set
			{
				SetValue(GridColumnsProperty, value);
			}
		}

		public ObservableCollection<ChartData> Targets
		{
			get
			{
				return (ObservableCollection<ChartData>)GetValue(TargetsProperty);
			}
			set
			{
				SetValue(TargetsProperty, value);
			}
		}

		public bool HighLight
		{
			get
			{
				return (bool)GetValue(HighLightProperty);
			}
			set
			{
				SetValue(HighLightProperty, value);
			}
		}

		public ERowSpaceMode RowSpaceMode
		{
			get
			{
				return (ERowSpaceMode)GetValue(RowSpaceModeProperty);
			}
			set
			{
				SetValue(RowSpaceModeProperty, value);
			}
		}

		public EDataRowSelectMode DataRowSelectMode
		{
			get
			{
				return (EDataRowSelectMode)GetValue(DataRowSelectModeProperty);
			}
			set
			{
				SetValue(DataRowSelectModeProperty, value);
			}
		}

		public ESampleSortMode SampleSortMode
		{
			get
			{
				return (ESampleSortMode)GetValue(SampleSortModeProperty);
			}
			set
			{
				SetValue(SampleSortModeProperty, value);
			}
		}

		public ESizeMode TableSizeMode
		{
			get
			{
				return (ESizeMode)GetValue(TableSizeModeProperty);
			}
			set
			{
				SetValue(TableSizeModeProperty, value);
			}
		}

		public bool UseScientific
		{
			get
			{
				return (bool)GetValue(UseScientificProperty);
			}
			set
			{
				SetValue(UseScientificProperty, value);
			}
		}

		public Experiment Experiment
		{
			get
			{
				return (Experiment)GetValue(ExperimentProperty);
			}
			set
			{
				SetValue(ExperimentProperty, value);
			}
		}

		public event RoutedEventHandler OnSelectionChanged
		{
			add
			{
				AddHandler(OnSelectionChangedRoutedEvent, value);
			}
			remove
			{
				RemoveHandler(OnSelectionChangedRoutedEvent, value);
			}
		}

		public event RoutedEventHandler OnChannelNoChanged
		{
			add
			{
				AddHandler(OnChannelNoChangedRoutedEvent, value);
			}
			remove
			{
				RemoveHandler(OnChannelNoChangedRoutedEvent, value);
			}
		}

		public void RaiseSelectionChanged()
		{
			RaiseEvent(new RoutedEventArgs
			{
				RoutedEvent = OnSelectionChangedRoutedEvent
			});
		}

		private static void OnColorModeChanged(object sender, DependencyPropertyChangedEventArgs args)
		{
			UCWellInfo uCWellInfo = sender as UCWellInfo;
			if (uCWellInfo != null)
			{
				uCWellInfo.ReloadGridData();
			}
		}

		private static void OnAutoWidthChanged(object sender, DependencyPropertyChangedEventArgs args)
		{
			UCWellInfo uCWellInfo = sender as UCWellInfo;
			if (uCWellInfo != null)
			{
				uCWellInfo.ultraGrid.DisplayLayout.AutoFitStyle = (uCWellInfo.AutoWidth ? AutoFitStyle.ResizeAllColumns : AutoFitStyle.None);
				if (uCWellInfo.AutoWidth && uCWellInfo.ultraGrid.DisplayLayout.Bands.Count > 0 && uCWellInfo.ultraGrid.DisplayLayout.Bands[0].Columns.Count > 0)
				{
					uCWellInfo.ultraGrid.DisplayLayout.Bands[0].Columns[0].CellAppearance.TextHAlign = HAlign.Center;
					uCWellInfo.ultraGrid.DisplayLayout.Bands[0].Columns[0].LockedWidth = !uCWellInfo.AutoWidth;
					uCWellInfo.ultraGrid.DisplayLayout.Bands[0].Columns[0].Header.Fixed = !uCWellInfo.AutoWidth;
				}
			}
		}

		private static void OnGridColumnsChanged(object sender, DependencyPropertyChangedEventArgs args)
		{
			UCWellInfo uCWellInfo = sender as UCWellInfo;
			if (uCWellInfo != null)
			{
				uCWellInfo.RefreshColumns();
			}
		}

		private static void OnTargetsChanged(object sender, DependencyPropertyChangedEventArgs args)
		{
			UCWellInfo uCWellInfo = sender as UCWellInfo;
		}

		private static void OnRowSpaceModeChanged(object sender, DependencyPropertyChangedEventArgs args)
		{
			UCWellInfo uCWellInfo = sender as UCWellInfo;
			if (uCWellInfo != null)
			{
				uCWellInfo.ReloadGridData();
			}
		}

		private static void OnDataRowSelectModeChanged(object sender, DependencyPropertyChangedEventArgs args)
		{
			UCWellInfo uCWellInfo = sender as UCWellInfo;
			if (uCWellInfo != null)
			{
				uCWellInfo.RefreshDataRowSelectMode();
			}
		}

		private static void OnSampleSortModeChanged(object sender, DependencyPropertyChangedEventArgs args)
		{
			UCWellInfo uCWellInfo = sender as UCWellInfo;
			if (uCWellInfo != null)
			{
				uCWellInfo.RefreshSortMode();
			}
		}

		private static void OnTableSizeModeChanged(object sender, DependencyPropertyChangedEventArgs args)
		{
			UCWellInfo uCWellInfo = sender as UCWellInfo;
			if (uCWellInfo != null)
			{
				int num = 9;
				switch (uCWellInfo.TableSizeMode)
				{
				case ESizeMode.Small:
					num = 9;
					break;
				case ESizeMode.Middle:
					num = 10;
					break;
				case ESizeMode.Large:
					num = 11;
					break;
				}
				uCWellInfo.ultraGrid.Font = new Font(uCWellInfo.ultraGrid.Font.Name, num);
				uCWellInfo.AutoSizeColumnSize();
			}
		}

		private static void OnUseScientificChanged(object sender, DependencyPropertyChangedEventArgs args)
		{
			UCWellInfo uCWellInfo = sender as UCWellInfo;
			if (uCWellInfo != null)
			{
				uCWellInfo.RefreshUseScientific();
			}
		}

		private static void OnExperimentChanged(object sender, DependencyPropertyChangedEventArgs args)
		{
			UCWellInfo uCWellInfo = sender as UCWellInfo;
			if (uCWellInfo != null)
			{
				uCWellInfo.InitMenu();
			}
		}

		public UCWellInfo()
		{
			InitializeComponent();
			InitUltraGrid();
		}

		public void Dispose()
		{
			ultraGrid.Dispose();
		}

		private void view_Filter(object sender, FilterEventArgs e)
		{
			ChartData chartData = e.Item as ChartData;
			if (chartData.WellCell.Well.Project == null || !chartData.WellCell.IsSelected || chartData.WellCell.Well.Sample == null)
			{
				chartData.WellCell.IsInfoSelected = false;
			}
			else
			{
				chartData.IsVisible = true;
				chartData.WellCell.IsInfoSelected = true;
			}
			e.Accepted = chartData.WellCell.IsInfoSelected;
		}

		public void FilterProject(string prjName)
		{
			ColumnFilter columnFilter = (from ColumnFilter s in ultraGrid.DisplayLayout.Bands[0].ColumnFilters
				where s.Column.Key == "WellCell.Well.Project.BasicInfo.Name"
				select s).FirstOrDefault();
			if (columnFilter != null)
			{
				columnFilter.ClearFilterConditions();
				if (!string.IsNullOrEmpty(prjName))
				{
					columnFilter.LogicalOperator = FilterLogicalOperator.Or;
					columnFilter.FilterConditions.Add(FilterComparisionOperator.Equals, prjName);
				}
			}
		}

		public void ClearTargetAndProjectFilter()
		{
			ColumnFilter columnFilter = (from ColumnFilter s in ultraGrid.DisplayLayout.Bands[0].ColumnFilters
				where s.Column.Key == "WellCell.Well.Project.BasicInfo.Name"
				select s).FirstOrDefault();
			if (columnFilter != null)
			{
				columnFilter.ClearFilterConditions();
				ColumnFilter columnFilter2 = (from ColumnFilter s in ultraGrid.DisplayLayout.Bands[0].ColumnFilters
					where s.Column.Key == "SampleTargetItem.TargetName"
					select s).FirstOrDefault();
				if (columnFilter2 != null)
				{
					columnFilter2.ClearFilterConditions();
				}
			}
		}

		public void FilterTarget(string prjName, string targetName)
		{
			if (!string.IsNullOrEmpty(prjName))
			{
				ColumnFilter columnFilter = (from ColumnFilter s in ultraGrid.DisplayLayout.Bands[0].ColumnFilters
					where s.Column.Key == "WellCell.Well.Project.BasicInfo.Name"
					select s).FirstOrDefault();
				if (columnFilter == null || string.IsNullOrEmpty(prjName))
				{
					return;
				}
				columnFilter.LogicalOperator = FilterLogicalOperator.Or;
				columnFilter.FilterConditions.Add(FilterComparisionOperator.Equals, prjName);
			}
			ColumnFilter columnFilter2 = (from ColumnFilter s in ultraGrid.DisplayLayout.Bands[0].ColumnFilters
				where s.Column.Key == "SampleTargetItem.TargetName"
				select s).FirstOrDefault();
			if (columnFilter2 != null && !string.IsNullOrEmpty(targetName))
			{
				columnFilter2.LogicalOperator = FilterLogicalOperator.Or;
				columnFilter2.FilterConditions.Add(FilterComparisionOperator.Equals, targetName);
			}
		}

		public void DisplayChannel(bool[] channelDisplay, bool all, bool refresh = true)
		{
			_ChannelDisplayInit = channelDisplay;
			if (_ChannelDisplayInit == null)
			{
				return;
			}
			ColumnFilter columnFilter = (from ColumnFilter s in ultraGrid.DisplayLayout.Bands[0].ColumnFilters
				where s.Column.Key == "SampleTargetItem.ChannelNo"
				select s).FirstOrDefault();
			if (columnFilter == null)
			{
				return;
			}
			columnFilter.ClearFilterConditions();
			if (!all)
			{
				columnFilter.LogicalOperator = FilterLogicalOperator.Or;
				for (int i = 0; i < channelDisplay.Count(); i++)
				{
					if (channelDisplay[i])
					{
						columnFilter.FilterConditions.Add(FilterComparisionOperator.Equals, i + 1);
					}
				}
			}
			if (refresh)
			{
				RefreshDataRowSelected();
				RaiseSelectionChanged();
			}
		}

		public List<int> GetDisplayChannelNo()
		{
			List<int> list = new List<int>();
			ColumnFilter columnFilter = (from ColumnFilter s in ultraGrid.DisplayLayout.Bands[0].ColumnFilters
				where s.Column.Key == "SampleTargetItem.ChannelNo"
				select s).FirstOrDefault();
			if (columnFilter == null || columnFilter.FilterConditions.Count == 0)
			{
				list.AddRange(new List<int> { 1, 2, 3, 4, 5, 6 });
				return list;
			}
			foreach (FilterCondition item in (IEnumerable)columnFilter.FilterConditions)
			{
				if (item.CompareValue is int)
				{
					list.Add(Convert.ToInt32(item.CompareValue));
				}
			}
			return list;
		}

		private void RefreshDataRowSelected()
		{
			List<ChartData> list = view.View.Cast<ChartData>().ToList();
			List<UltraGridRow> list2 = new List<UltraGridRow>();
			if (DataRowSelectMode != EDataRowSelectMode.Cell)
			{
				if (ultraGrid.Selected.Columns.Count > 0)
				{
					SelectAllGridData();
				}
				else
				{
					list2.AddRange(from UltraGridRow s in ultraGrid.Selected.Rows
						where !s.IsFilteredOut
						select s);
					for (int num = list2.Count - 1; num >= 0; num--)
					{
						UltraGridRow ultraGridRow = list2[num];
						if (ultraGridRow.ListIndex >= 0 && ultraGridRow.ListIndex < list.Count)
						{
							ChartData data = list[ultraGridRow.ListIndex];
							List<UltraGridRow> list3 = null;
							switch (DataRowSelectMode)
							{
							case EDataRowSelectMode.Well:
								list3 = ultraGrid.Rows.Where((UltraGridRow s) => !s.Selected && !s.IsFilteredOut && list[s.ListIndex].WellCell.Well == data.WellCell.Well).ToList();
								break;
							case EDataRowSelectMode.Sample:
								list3 = ultraGrid.Rows.Where((UltraGridRow s) => !s.Selected && !s.IsFilteredOut && list[s.ListIndex].WellCell.Well.Sample == data.WellCell.Well.Sample).ToList();
								break;
							}
							if (list3 != null)
							{
								foreach (UltraGridRow item in list3)
								{
									item.Selected = true;
								}
							}
						}
					}
				}
			}
			else if (DataRowSelectMode == EDataRowSelectMode.Cell)
			{
				if (ultraGrid.Selected.Columns.Count > 0)
				{
					list2.AddRange(ultraGrid.Rows);
				}
				else
				{
					foreach (UltraGridCell cell in ultraGrid.Selected.Cells)
					{
						if (!cell.Row.IsFilteredOut)
						{
							list2.Add(cell.Row);
						}
					}
				}
			}
			foreach (UltraGridRow row in ultraGrid.Rows)
			{
				if (row.ListIndex >= 0 && row.ListIndex < list.Count)
				{
					list[row.ListIndex].IsVisible = (row.Selected || list2.Contains(row)) && !row.IsFilteredOut;
				}
			}
		}

		private void RegisterChartDataEvent()
		{
			foreach (ChartData target in Targets)
			{
				if (_RegisteredItem.ContainsKey(target))
				{
					break;
				}
				target.Event += chartData_Event;
				target.SampleTargetItem.Event += SampleTargetItem_Event;
				_RegisteredItem.Add(target, true);
			}
		}

		public void RefreshData()
		{
			if (view.View != null)
			{
				view.View.Refresh();
			}
			else
			{
				view.Source = Targets;
				view.Filter += view_Filter;
				RefreshSortMode();
			}
			RegisterChartDataEvent();
			RefreshColumns();
			RefreshDataRowCount();
			SelectAllGridData();
			RefreshDataRowSelected();
			RaiseSelectionChanged();
			AutoSizeColumnSize();
		}

		private void chartData_Event(object sender, EventArgs e)
		{
			PropertyChangedEventArgsEx propertyChangedEventArgsEx = e as PropertyChangedEventArgsEx;
			if (propertyChangedEventArgsEx != null && HighLight && propertyChangedEventArgsEx.PropertyName == "HighLight")
			{
				List<ChartData> list = view.View.Cast<ChartData>().ToList();
				int index = list.IndexOf(sender as ChartData);
				UltraGridRow ultraGridRow = ultraGrid.Rows.Where((UltraGridRow s) => s.ListIndex == index).FirstOrDefault();
				if (ultraGridRow != null)
				{
					ultraGridRow.Appearance = (((ChartData)sender).HighLight ? appearanceHighLight : null);
				}
				ultraGrid.ActiveRow = ultraGridRow;
			}
		}

		private void SampleTargetItem_Event(object sender, EventArgs e)
		{
			PropertyChangedEventArgsEx propertyChangedEventArgsEx = e as PropertyChangedEventArgsEx;
			if (propertyChangedEventArgsEx != null && propertyChangedEventArgsEx.PropertyName == "LineColor")
			{
				ReloadGridData();
			}
		}

		private void RefreshDataRowSelectMode()
		{
			switch (DataRowSelectMode)
			{
			case EDataRowSelectMode.Cell:
				ultraGrid.DisplayLayout.Override.CellClickAction = CellClickAction.CellSelect;
				break;
			case EDataRowSelectMode.Target:
			case EDataRowSelectMode.Well:
			case EDataRowSelectMode.Sample:
				ultraGrid.DisplayLayout.Override.CellClickAction = CellClickAction.RowSelect;
				break;
			}
		}

		private void RefreshSortMode()
		{
			if (!_CustomSort)
			{
				view.SortDescriptions.Clear();
				SortDescription item;
				switch (SampleSortMode)
				{
				case ESampleSortMode.Column:
					item = default(SortDescription);
					item.PropertyName = "WellCell.Well.Sample.Wells[0].ColumnIndex";
					item.Direction = ListSortDirection.Ascending;
					view.SortDescriptions.Add(item);
					break;
				case ESampleSortMode.Row:
					item = default(SortDescription);
					item.PropertyName = "WellCell.Well.Sample.Wells[0].RowIndex";
					item.Direction = ListSortDirection.Ascending;
					view.SortDescriptions.Add(item);
					break;
				case ESampleSortMode.Module:
					item = default(SortDescription);
					item.PropertyName = "WellCell.Well.Sample.Wells[0].ModelA";
					item.Direction = ListSortDirection.Descending;
					view.SortDescriptions.Add(item);
					item = default(SortDescription);
					item.PropertyName = "WellCell.Well.Sample.Wells[0].RowIndex";
					item.Direction = ListSortDirection.Ascending;
					view.SortDescriptions.Add(item);
					break;
				}
				item = default(SortDescription);
				item.PropertyName = "WellCell.Well.Sample";
				item.Direction = ListSortDirection.Ascending;
				view.SortDescriptions.Add(item);
				item = default(SortDescription);
				item.PropertyName = "WellCell.Well.MultiTubeID";
				item.Direction = ListSortDirection.Ascending;
				view.SortDescriptions.Add(item);
				item = default(SortDescription);
				item.PropertyName = "SampleTargetItem.ChannelNo";
				item.Direction = ListSortDirection.Ascending;
				view.SortDescriptions.Add(item);
				ReloadGridData();
			}
		}

		private void InitUltraGrid()
		{
			numberFormatInfo = CultureInfo.CurrentUICulture.NumberFormat.Clone() as NumberFormatInfo;
			numberFormatInfo.PositiveInfinitySymbol = Utility.GetMessage("NoCt");
			numberFormatInfo.NaNSymbol = string.Empty;
			Infragistics.Win.Appearance appearance = new Infragistics.Win.Appearance();
			Infragistics.Win.Appearance appearance2 = new Infragistics.Win.Appearance();
			Infragistics.Win.Appearance appearance3 = new Infragistics.Win.Appearance();
			Infragistics.Win.Appearance appearance4 = new Infragistics.Win.Appearance();
			Infragistics.Win.Appearance appearance5 = new Infragistics.Win.Appearance();
			Infragistics.Win.Appearance appearance6 = new Infragistics.Win.Appearance();
			Infragistics.Win.Appearance appearance7 = new Infragistics.Win.Appearance();
			Infragistics.Win.Appearance appearance8 = new Infragistics.Win.Appearance();
			Infragistics.Win.Appearance appearance9 = new Infragistics.Win.Appearance();
			Infragistics.Win.Appearance appearance10 = new Infragistics.Win.Appearance();
			Infragistics.Win.Appearance appearance11 = new Infragistics.Win.Appearance();
			Infragistics.Win.Appearance appearance12 = new Infragistics.Win.Appearance();
			((ISupportInitialize)ultraGrid).BeginInit();
			appearance.BackColor = System.Drawing.SystemColors.Window;
			appearance.BorderColor = System.Drawing.SystemColors.InactiveCaption;
			ultraGrid.DisplayLayout.Appearance = appearance;
			ultraGrid.DisplayLayout.BorderStyle = UIElementBorderStyle.Solid;
			ultraGrid.DisplayLayout.CaptionVisible = DefaultableBoolean.False;
			appearance2.BackColor = System.Drawing.SystemColors.ActiveBorder;
			appearance2.BackColor2 = System.Drawing.SystemColors.ControlDark;
			appearance2.BackGradientStyle = GradientStyle.Vertical;
			appearance2.BorderColor = System.Drawing.SystemColors.Window;
			ultraGrid.DisplayLayout.GroupByBox.Appearance = appearance2;
			appearance3.ForeColor = System.Drawing.SystemColors.GrayText;
			ultraGrid.DisplayLayout.GroupByBox.BandLabelAppearance = appearance3;
			ultraGrid.DisplayLayout.GroupByBox.BorderStyle = UIElementBorderStyle.Solid;
			appearance4.BackColor = System.Drawing.SystemColors.ControlLightLight;
			appearance4.BackColor2 = System.Drawing.SystemColors.Control;
			appearance4.BackGradientStyle = GradientStyle.Horizontal;
			appearance4.ForeColor = System.Drawing.SystemColors.GrayText;
			ultraGrid.DisplayLayout.GroupByBox.PromptAppearance = appearance4;
			ultraGrid.DisplayLayout.MaxColScrollRegions = 1;
			ultraGrid.DisplayLayout.MaxRowScrollRegions = 1;
			appearance5.BackColor = System.Drawing.SystemColors.Window;
			appearance5.ForeColor = System.Drawing.SystemColors.ControlText;
			ultraGrid.DisplayLayout.Override.ActiveCellAppearance = appearance5;
			appearance6.BackColor = System.Drawing.SystemColors.Highlight;
			appearance6.ForeColor = System.Drawing.SystemColors.HighlightText;
			ultraGrid.DisplayLayout.Override.ActiveRowAppearance = appearance6;
			ultraGrid.DisplayLayout.Override.BorderStyleCell = UIElementBorderStyle.Dotted;
			ultraGrid.DisplayLayout.Override.BorderStyleRow = UIElementBorderStyle.Dotted;
			appearance7.BackColor = System.Drawing.SystemColors.Window;
			ultraGrid.DisplayLayout.Override.CardAreaAppearance = appearance7;
			appearance8.BorderColor = Color.Silver;
			appearance8.TextTrimming = Infragistics.Win.TextTrimming.EllipsisCharacter;
			ultraGrid.DisplayLayout.Override.CellAppearance = appearance8;
			ultraGrid.DisplayLayout.Override.CellClickAction = CellClickAction.EditAndSelectText;
			ultraGrid.DisplayLayout.Override.CellPadding = 0;
			appearance9.BackColor = System.Drawing.SystemColors.Control;
			appearance9.BackColor2 = System.Drawing.SystemColors.ControlDark;
			appearance9.BackGradientAlignment = GradientAlignment.Element;
			appearance9.BackGradientStyle = GradientStyle.Horizontal;
			appearance9.BorderColor = System.Drawing.SystemColors.Window;
			ultraGrid.DisplayLayout.Override.GroupByRowAppearance = appearance9;
			appearance10.TextHAlignAsString = "Left";
			ultraGrid.DisplayLayout.Override.HeaderAppearance = appearance10;
			ultraGrid.DisplayLayout.Override.HeaderClickAction = HeaderClickAction.Select;
			ultraGrid.DisplayLayout.Override.HeaderStyle = HeaderStyle.WindowsXPCommand;
			appearance11.BackColor = System.Drawing.SystemColors.Window;
			appearance11.BorderColor = Color.Silver;
			ultraGrid.DisplayLayout.Override.RowAppearance = appearance11;
			ultraGrid.DisplayLayout.Override.RowSelectors = DefaultableBoolean.False;
			appearance12.BackColor = System.Drawing.SystemColors.ControlLight;
			ultraGrid.DisplayLayout.Override.TemplateAddRowAppearance = appearance12;
			ultraGrid.DisplayLayout.ScrollBounds = ScrollBounds.ScrollToFill;
			ultraGrid.DisplayLayout.ScrollStyle = ScrollStyle.Immediate;
			ultraGrid.DisplayLayout.ViewStyleBand = ViewStyleBand.OutlookGroupBy;
			ultraGrid.Name = "ultraGrid";
			ultraGrid.Dock = DockStyle.Fill;
			ultraGrid.TabIndex = 0;
			ultraGrid.Text = "ultraGrid1";
			ultraGrid.DisplayLayout.BorderStyle = UIElementBorderStyle.None;
			ultraGrid.DisplayLayout.GroupByBox.Hidden = true;
			InitDataSource();
			InitCustomFilter();
			((ISupportInitialize)ultraGrid).EndInit();
			ultraGrid.InitializeLayout += ultraGrid_InitializeLayout;
			ultraGrid.MouseUp += ultraGrid_MouseUp;
			ultraGrid.MouseDown += ultraGrid_MouseDown;
			ultraGrid.MouseMove += ultraGrid_MouseMove;
			ultraGrid.MouseLeave += ultraGrid_MouseLeave;
			ultraGrid.KeyDown += ultraGrid_KeyDown;
			ultraGrid.Click += ultraGrid_Click;
			ultraGrid.BeforeRowResize += ultraGrid_BeforeRowResize;
			ultraGrid.AfterRowFilterChanged += ultraGrid_AfterRowFilterChanged;
			ultraGrid.AfterSelectChange += ultraGrid_AfterSelectChange;
			appearanceHighLight.FontData.Bold = DefaultableBoolean.True;
			windowsFormsHost.Child = ultraGrid;
		}

		private void InitCustomFilter()
		{
			UltraGridFilterUIProvider ultraGridFilterUIProvider = new UltraGridFilterUIProvider();
			ultraGrid.DisplayLayout.Override.FilterUIProvider = ultraGridFilterUIProvider;
			ultraGridFilterUIProvider.AfterMenuPopulate += filterUIProvider_AfterMenuPopulate;
			ultraGridFilterUIProvider.ButtonToolClick += filterUIProvider_ButtonToolClick;
		}

		private void filterUIProvider_ButtonToolClick(object sender, ButtonToolClickEventArgs e)
		{
			string id = e.Tool.Id;
			if (id == Utility.GetMessage("not_sort"))
			{
				ultraGrid.DisplayLayout.Bands[0].SortedColumns.Clear();
				_CustomSort = false;
				RefreshSortMode();
				AutoSizeColumnSize();
			}
			else if (id == Utility.GetMessage("Ascending"))
			{
				ultraGrid.DisplayLayout.Bands[0].SortedColumns.Clear();
				ultraGrid.DisplayLayout.Bands[0].SortedColumns.Add(e.ColumnFilter.Column.Key, false);
				_CustomSort = true;
				RefreshSortMode();
				AutoSizeColumnSize();
			}
			else if (id == Utility.GetMessage("Descending"))
			{
				ultraGrid.DisplayLayout.Bands[0].SortedColumns.Clear();
				ultraGrid.DisplayLayout.Bands[0].SortedColumns.Add(e.ColumnFilter.Column.Key, true);
				_CustomSort = true;
				RefreshSortMode();
				AutoSizeColumnSize();
			}
			else if (id == Utility.GetMessage("sort_well_plate_column"))
			{
				ultraGrid.DisplayLayout.Bands[0].SortedColumns.Clear();
				SampleSortMode = ESampleSortMode.Column;
			}
			else if (id == Utility.GetMessage("sort_well_plate_line"))
			{
				ultraGrid.DisplayLayout.Bands[0].SortedColumns.Clear();
				SampleSortMode = ESampleSortMode.Row;
			}
			else if (id == Utility.GetMessage("sort_well_plate_line_module_a"))
			{
				ultraGrid.DisplayLayout.Bands[0].SortedColumns.Clear();
				SampleSortMode = ESampleSortMode.Module;
			}
			else
			{
				if (!(id == Utility.GetMessage("adv_filter")))
				{
					return;
				}
				string key = currentColumnFilter.Column.Key;
				CustomFilterWindow customFilterWindow = new CustomFilterWindow();
				customFilterWindow.Owner = Utility.GetMainWindow();
				customFilterWindow.NumberFilter = IsNumberKey(key);
				customFilterWindow.Caption = currentColumnFilter.Column.Header.Caption;
				customFilterWindow.LogicOperator = currentColumnFilter.LogicalOperator;
				customFilterWindow.ClearFilter();
				if (currentColumnFilter.FilterConditions.Count > 0 && currentColumnFilter.FilterConditions.Count <= 2)
				{
					customFilterWindow.FirstOperator = currentColumnFilter.FilterConditions[0].ComparisionOperator;
					customFilterWindow.FirstValue = currentColumnFilter.FilterConditions[0].CompareValue;
					if (currentColumnFilter.FilterConditions.Count == 2)
					{
						customFilterWindow.SecondOperator = currentColumnFilter.FilterConditions[1].ComparisionOperator;
						customFilterWindow.SecondValue = currentColumnFilter.FilterConditions[1].CompareValue;
					}
				}
				if (customFilterWindow.ShowDialog() == true)
				{
					currentColumnFilter.FilterConditions.Clear();
					currentColumnFilter.LogicalOperator = customFilterWindow.LogicOperator;
					if (customFilterWindow.HasFirstFilter())
					{
						currentColumnFilter.FilterConditions.Add(customFilterWindow.FirstOperator, customFilterWindow.FirstValue);
					}
					if (customFilterWindow.HasSecondFilter())
					{
						currentColumnFilter.FilterConditions.Add(customFilterWindow.SecondOperator, customFilterWindow.SecondValue);
					}
				}
			}
		}

		private void filterUIProvider_AfterMenuPopulate(object sender, AfterMenuPopulateEventArgs e)
		{
			UltraGridColumn column = ((e.ColumnFilter != null) ? e.ColumnFilter.Column : null);
			SetupFilterTools(column, e.MenuItems);
			currentColumnFilter = e.ColumnFilter;
		}

		private void SetupFilterTools(UltraGridColumn column, IList<FilterTool> toolList)
		{
			if (column == null)
			{
				return;
			}
			string key = column.Key;
			string text;
			if ((text = key) != null && text == "WellCell.Well.CellName")
			{
				toolList.Clear();
				toolList.Add(new FilterButtonTool(Utility.GetMessage("sort_well_plate_column"), Utility.GetMessage("sort_well_plate_column"))
				{
					Checked = (SampleSortMode == ESampleSortMode.Column)
				});
				toolList.Add(new FilterButtonTool(Utility.GetMessage("sort_well_plate_line"), Utility.GetMessage("sort_well_plate_line"))
				{
					Checked = (SampleSortMode == ESampleSortMode.Row)
				});
				if (Experiment.Device.Model == Device.DeviceModel_96P || Experiment.Device.Model == Device.DeviceModel_40P || string.IsNullOrEmpty(Experiment.Device.Model))
				{
					toolList.Add(new FilterButtonTool(Utility.GetMessage("sort_well_plate_line_module_a"), Utility.GetMessage("sort_well_plate_line_module_a"))
					{
						Checked = (SampleSortMode == ESampleSortMode.Module)
					});
				}
				return;
			}
			toolList.Insert(0, new FilterButtonTool(Utility.GetMessage("not_sort"), Utility.GetMessage("not_sort"))
			{
				Checked = (column.SortIndicator == SortIndicator.None)
			});
			toolList.Insert(1, new FilterButtonTool(Utility.GetMessage("Ascending"), Utility.GetMessage("Ascending"))
			{
				Checked = (column.SortIndicator == SortIndicator.Ascending)
			});
			toolList.Insert(2, new FilterButtonTool(Utility.GetMessage("Descending"), Utility.GetMessage("Descending"))
			{
				Checked = (column.SortIndicator == SortIndicator.Descending)
			});
			toolList[3].DisplayText = Utility.GetMessage("clear_filter");
			toolList.RemoveAt(4);
			if (key != "SampleTargetItem.ChannelNo")
			{
				toolList.Insert(4, new FilterButtonTool(Utility.GetMessage("adv_filter"), Utility.GetMessage("adv_filter"))
				{
					Checked = toolList[3].Enabled
				});
				if (IsNumberKey(key))
				{
					toolList.RemoveAt(5);
				}
			}
		}

		private ConditionValueAppearance CreateFormulaConditionValueAppearance(IFormulaProvider formulaProvider)
		{
			ConditionValueAppearance conditionValueAppearance = new ConditionValueAppearance();
			ConditionGroup conditionGroup = new ConditionGroup();
			conditionGroup.CombineOperator = LogicalOperator.And;
			OperatorCondition condition = new OperatorCondition(ConditionOperator.NotEquals, Utility.GetMessage("NoCt"));
			OperatorCondition condition2 = new OperatorCondition(ConditionOperator.LessThan, 27);
			Infragistics.Win.Appearance appearance = new Infragistics.Win.Appearance();
			appearance.ForeColor = Color.Red;
			conditionGroup.Add(condition);
			conditionGroup.Add(condition2);
			conditionValueAppearance.Add(conditionGroup, appearance);
			conditionGroup = new ConditionGroup();
			conditionGroup.CombineOperator = LogicalOperator.And;
			condition = new OperatorCondition(ConditionOperator.NotEquals, Utility.GetMessage("NoCt"));
			condition2 = new OperatorCondition(ConditionOperator.GreaterThanOrEqualTo, 27);
			appearance = new Infragistics.Win.Appearance();
			appearance.ForeColor = Color.Blue;
			conditionGroup.Add(condition);
			conditionGroup.Add(condition2);
			conditionValueAppearance.Add(conditionGroup, appearance);
			return conditionValueAppearance;
		}

		private void InitDataSource()
		{
			informationTable.CellDataRequested += informationTable_CellDataRequested;
			informationTable.ReadOnly = true;
			ultraGrid.DisplayLayout.LoadStyle = LoadStyle.LoadOnDemand;
			ultraGrid.DataSource = informationTable;
		}

		private void SelectAllGridData()
		{
			ultraGrid.Selected.Rows.AddRange((UltraGridRow[])ultraGrid.Rows.All);
		}

		private void RefreshDataRowCount()
		{
			if (view.View != null)
			{
				informationTable.Rows.SetCount(view.View.Cast<ChartData>().Count());
				ReloadGridData();
				if (_CustomSort)
				{
					ultraGrid.DisplayLayout.Bands[0].SortedColumns.RefreshSort(false);
				}
			}
		}

		public void ReloadGridData()
		{
			ultraGrid.Rows.Refresh(RefreshRow.ReloadData);
		}

		private void RefreshUseScientific()
		{
			foreach (UltraGridColumn column in ultraGrid.DisplayLayout.Bands[0].Columns)
			{
				if (column.Key == "SampleTargetItem.Result.CnMean" || column.Key == "SampleTargetItem.Result.CnSD")
				{
					column.Format = (UseScientific ? "0.000E0" : "#,0.00");
				}
			}
			ReloadGridData();
			AutoSizeColumnSize();
		}

		private List<List<string>> GetSelectedData()
		{
			List<List<string>> list = new List<List<string>>();
			List<ChartData> list2 = view.View.Cast<ChartData>().ToList();
			List<UltraGridCell> list3 = new List<UltraGridCell>();
			List<UltraGridColumn> list4 = new List<UltraGridColumn>();
			List<UltraGridRow> list5 = new List<UltraGridRow>();
			if (ultraGrid.Selected.Rows.Count > 0)
			{
				list5.AddRange(from UltraGridRow s in ultraGrid.Selected.Rows
					where s.VisibleIndex >= 0 && !s.IsFilteredOut
					select s);
				list4.AddRange(from UltraGridColumn s in ultraGrid.DisplayLayout.Bands[0].Columns
					where !s.Hidden
					select s);
				foreach (UltraGridRow item in list5)
				{
					foreach (UltraGridColumn item2 in list4)
					{
						list3.Add(item.Cells[item2]);
					}
				}
			}
			if (ultraGrid.Selected.Columns.Count > 0)
			{
				List<UltraGridRow> list6 = ultraGrid.Rows.Where((UltraGridRow s) => s.VisibleIndex >= 0 && !s.IsFilteredOut).ToList();
				List<UltraGridColumn> list7 = (from Infragistics.Win.UltraWinGrid.ColumnHeader s in ultraGrid.Selected.Columns
					select s.Column into s
					where !s.Hidden
					select s).ToList();
				list5.AddRange(list6);
				list4.AddRange(list7);
				foreach (UltraGridRow item3 in list6)
				{
					foreach (UltraGridColumn item4 in list7)
					{
						list3.Add(item3.Cells[item4]);
					}
				}
			}
			if (ultraGrid.Selected.Cells.Count > 0)
			{
				List<UltraGridCell> list8 = (from UltraGridCell s in ultraGrid.Selected.Cells
					where s.Row.VisibleIndex >= 0 && !s.Row.IsFilteredOut && !s.Column.Hidden
					select s).ToList();
				List<UltraGridColumn> collection = (from s in list8
					orderby s.Column.Header.VisiblePosition
					select s.Column).Distinct().ToList();
				List<UltraGridRow> collection2 = (from s in list8
					orderby s.Row.VisibleIndex
					select s.Row).Distinct().ToList();
				list5.AddRange(collection2);
				list4.AddRange(collection);
				list3.AddRange(list8);
			}
			list5 = (from s in list5.Distinct()
				orderby s.VisibleIndex
				select s).ToList();
			list4 = (from s in list4.Distinct()
				orderby s.Header.VisiblePosition
				select s).ToList();
			list3 = list3.Distinct().ToList();
			List<string> list9 = new List<string>();
			foreach (UltraGridColumn item5 in list4)
			{
				list9.Add(item5.Header.Caption);
			}
			list.Add(list9);
			for (int i = 0; i < list5.Count; i++)
			{
				list9 = new List<string>();
				for (int j = 0; j < list4.Count; j++)
				{
					if (list3.Contains(list5[i].Cells[list4[j]]))
					{
						object columnData = GetColumnData(list4[j].Key, list2[list5[i].ListIndex], false);
						list9.Add((columnData == null) ? null : columnData.ToString());
					}
					else
					{
						list9.Add(string.Empty);
					}
				}
				list.Add(list9);
			}
			return list;
		}

		private void CopySelectedToClipBoard()
		{
			List<List<string>> selectedData = GetSelectedData();
			StringBuilder stringBuilder = new StringBuilder();
			for (int i = 1; i < selectedData.Count; i++)
			{
				List<string> list = selectedData[i];
				for (int j = 0; j < list.Count; j++)
				{
					if (j > 0)
					{
						stringBuilder.Append("\t");
					}
					stringBuilder.Append(list[j]);
				}
				if (i != selectedData.Count - 1)
				{
					stringBuilder.AppendLine(string.Empty);
				}
			}
			SLANClipboard.SetToClipboard(stringBuilder.ToString());
		}

		private bool IsNumberKey(string key)
		{
			if (!(key == "SampleTargetItem.Result.CnValue"))
			{
				return IsDisplayNumberKey(key);
			}
			return true;
		}

		private bool IsDisplayNumberKey(string key)
		{
			switch (key)
			{
			default:
				if (key.IndexOf("SampleTargetItem.Result.Tm") == -1 && key.IndexOf("SampleTargetItem.Result.Rm") == -1 && key.IndexOf("SampleTargetItem.Result.Wm") == -1 && key.IndexOf("SampleTargetItem.Result.Ym") == -1 && !(key == "SampleTargetItem.ChannelNo") && !(key == "SampleTargetItem.Result.QualityFactor"))
				{
					return key == "WellCell.Well.Result.QualityFactor";
				}
				break;
			case "SampleTargetItem.Result.CtValue":
			case "SampleTargetItem.Result.CtMean":
			case "SampleTargetItem.Result.CtSD":
			case "SampleTargetItem.Result.CtCV":
			case "SampleTargetItem.Result.CnSD":
			case "SampleTargetItem.Result.CnMean":
			case "SampleTargetItem.Result.CnCV":
			case "SampleTargetItem.Result.RnValue":
				break;
			}
			return true;
		}

		public void AutoSizeColumnSize()
		{
			if (view.View == null)
			{
				return;
			}
			Graphics graphics = ultraGrid.CreateGraphics();
			List<ChartData> list = view.View.Cast<ChartData>().ToList();
			foreach (UltraGridColumn column in ultraGrid.DisplayLayout.Bands[0].Columns)
			{
				string caption = column.Header.Caption;
				caption = ((column.AllowRowFiltering == DefaultableBoolean.False) ? (caption + "W") : (caption + "WW"));
				if (ultraGrid.DisplayLayout.Bands[0].SortedColumns.Contains(column))
				{
					caption += "WW";
				}
				string text = string.Empty;
				if (column.Key == "SampleTargetItem.LineColor")
				{
					text = "WWW";
				}
				else
				{
					foreach (UltraGridRow item in ultraGrid.Rows.Where((UltraGridRow s) => !s.IsFilteredOut).ToList())
					{
						object columnData = GetColumnData(column.Key, list[item.ListIndex], column.Key == "SampleTargetItem.Result.CnValue");
						string text2 = ((columnData == null) ? null : columnData.ToString());
						if (!string.IsNullOrEmpty(text2) && text.Length < text2.Length)
						{
							text = text2;
						}
					}
					text += "W";
				}
				int num = (int)graphics.MeasureString(caption, ultraGrid.Font).Width;
				int num2 = (int)graphics.MeasureString(text, ultraGrid.Font).Width + 4 + 4;
				column.Width = ((num > num2) ? num : num2);
			}
			graphics.Dispose();
		}

		public void SetColunmNoFilter()
		{
			shouldFilter = false;
			List<UltraGridColumn> list = (from UltraGridColumn s in ultraGrid.DisplayLayout.Bands[0].Columns
				where s.Key.IndexOf("WellCell.Well.Sample.PatientInfoCustomData.") == 0
				select s).ToList();
			foreach (UltraGridColumn item in list)
			{
				item.AllowRowFiltering = DefaultableBoolean.False;
			}
		}

		public void RefreshColumns()
		{
			if (view.View == null)
			{
				return;
			}
			int num = 0;
			List<UltraDataColumn> list = (from UltraDataColumn s in informationTable.Band.Columns
				where s.Key.IndexOf("WellCell.Well.Sample.PatientInfoCustomData.") == 0
				select s).ToList();
			int num2 = 0;
			if (Targets.Count() > 0)
			{
				num2 = Targets[0].WellCell.Well.Sample.PatientInfo.CustomData.Count();
			}
			foreach (UltraDataColumn item in list)
			{
				string text = item.Key.ToString();
				if (text.IndexOf("WellCell.Well.Sample.PatientInfoCustomData.") == 0)
				{
					text = text.Replace("WellCell.Well.Sample.PatientInfoCustomData.", string.Empty);
					if (int.Parse(text) >= num2)
					{
						informationTable.Band.Columns.Remove(item);
					}
				}
			}
			foreach (ColumnInfo column in GridColumns.Columns)
			{
				switch (WellInfoType)
				{
				case EWellInfoType.Edit:
					if ((column.Info & 1) != 1 || column.FieldName == "SampleTargetItem.LineColor")
					{
						continue;
					}
					break;
				case EWellInfoType.Run:
					if (column.Info == 2 && Experiment.Type != EProjectType.FastCal)
					{
						continue;
					}
					break;
				}
				if (column.IsCustomColumn())
				{
					InsertNewColumn("WellCell.Well.Sample.PatientInfoCustomData." + column.FieldIndex, num++, column.Header, column.Visibility);
				}
				else
				{
					if (string.IsNullOrEmpty(column.FieldName))
					{
						continue;
					}
					if (column.FieldName == "SampleTargetItem.Result.Tm")
					{
						int tmCount = GetTmCount();
						list = (from UltraDataColumn s in informationTable.Band.Columns
							where s.Key.IndexOf("SampleTargetItem.Result.Tm") == 0 || s.Key.IndexOf("SampleTargetItem.Result.Rm") == 0 || s.Key.IndexOf("SampleTargetItem.Result.Ym") == 0 || s.Key.IndexOf("SampleTargetItem.Result.Wm") == 0
							select s).ToList();
						foreach (UltraDataColumn item2 in list)
						{
							string text2 = item2.Key.ToString();
							if (text2.IndexOf("SampleTargetItem.Result.Tm") == 0)
							{
								text2 = text2.Replace("SampleTargetItem.Result.Tm", string.Empty);
								if (int.Parse(text2) >= tmCount)
								{
									informationTable.Band.Columns.Remove(item2);
								}
							}
							else if (text2.IndexOf("SampleTargetItem.Result.Rm") == 0)
							{
								text2 = text2.Replace("SampleTargetItem.Result.Rm", string.Empty);
								if (int.Parse(text2) >= tmCount)
								{
									informationTable.Band.Columns.Remove(item2);
								}
							}
							else if (text2.IndexOf("SampleTargetItem.Result.Ym") == 0)
							{
								text2 = text2.Replace("SampleTargetItem.Result.Ym", string.Empty);
								if (int.Parse(text2) >= tmCount)
								{
									informationTable.Band.Columns.Remove(item2);
								}
							}
							else if (text2.IndexOf("SampleTargetItem.Result.Wm") == 0)
							{
								text2 = text2.Replace("SampleTargetItem.Result.Wm", string.Empty);
								if (int.Parse(text2) >= tmCount)
								{
									informationTable.Band.Columns.Remove(item2);
								}
							}
						}
						ColumnInfo columnInfo = GridColumns.Columns.Where((ColumnInfo s) => s.FieldName == "SampleTargetItem.Result.Rm").FirstOrDefault();
						ColumnInfo columnInfo2 = GridColumns.Columns.Where((ColumnInfo s) => s.FieldName == "SampleTargetItem.Result.Ym").FirstOrDefault();
						ColumnInfo columnInfo3 = GridColumns.Columns.Where((ColumnInfo s) => s.FieldName == "SampleTargetItem.Result.Wm").FirstOrDefault();
						for (int i = 0; i < tmCount; i++)
						{
							InsertNewColumn("SampleTargetItem.Result.Tm" + i, num++, column.Header + (i + 1), column.Visibility);
							InsertNewColumn("SampleTargetItem.Result.Rm" + i, num++, columnInfo.Header + (i + 1), columnInfo.Visibility);
							InsertNewColumn("SampleTargetItem.Result.Ym" + i, num++, columnInfo2.Header + (i + 1), columnInfo2.Visibility);
							if (columnInfo3.Display)
							{
								InsertNewColumn("SampleTargetItem.Result.Wm" + i, num++, columnInfo3.Header + (i + 1), columnInfo3.Visibility);
							}
						}
					}
					else
					{
						if (column.FieldName == "SampleTargetItem.Result.Rm" || column.FieldName == "SampleTargetItem.Result.Ym" || column.FieldName == "SampleTargetItem.Result.Wm")
						{
							continue;
						}
						if (column.FieldName == "SampleTargetItem.Result.MidValue")
						{
							list = (from UltraDataColumn s in informationTable.Band.Columns
								where s.Key.IndexOf("SampleTargetItem.Result.MidValue") == 0 || s.Key.IndexOf("WellCell.Well.Result.MidValue") == 0 || s.Key.IndexOf("WellCell.Well.Sample.Result.MidValue") == 0
								select s).ToList();
							List<KeyValuePair> midValue = GetMidValue(true);
							foreach (UltraDataColumn item3 in list)
							{
								if (!IsExist(midValue, item3.Key))
								{
									informationTable.Band.Columns.Remove(item3);
								}
							}
							foreach (KeyValuePair item4 in midValue)
							{
								InsertNewColumn(item4.Key.ToString(), num++, item4.Value.ToString(), column.Visibility);
							}
						}
						else if (column.FieldName == "SampleTargetItem.Result.ConclusionList")
						{
							InsertNewColumn("SampleTargetItem.Result.ConclusionList".ToString(), num++, Utility.GetMessage("Prj_TargetConclusion"), column.Visibility);
							InsertNewColumn("WellCell.Well.Result.ConclusionList".ToString(), num++, Utility.GetMessage("Prj_WellConclusion"), column.Visibility);
							InsertNewColumn("WellCell.Well.Sample.Result.ConclusionList".ToString(), num++, Utility.GetMessage("Prj_SampleConclusion"), column.Visibility);
						}
						else
						{
							bool visible = column.Visibility;
							if (WellInfoType == EWellInfoType.Edit && (column.Info & 1) == 1)
							{
								visible = true;
							}
							InsertNewColumn(column.FieldName, num++, column.Header, visible);
						}
					}
				}
			}
			RefreshSelectedStyle();
		}

		private List<KeyValuePair> GetMidValue(bool all = false)
		{
			List<KeyValuePair> list = new List<KeyValuePair>();
			IEnumerable<ChartData> enumerable = (all ? Targets : view.View.Cast<ChartData>());
			foreach (ChartData item in enumerable)
			{
				foreach (MidValue midValue in item.WellCell.Well.Sample.Result.MidValues)
				{
					string key = "WellCell.Well.Sample.Result.MidValue" + midValue.Name;
					if (!IsExist(list, key))
					{
						list.Add(new KeyValuePair
						{
							Key = key,
							Value = midValue.Name
						});
					}
				}
				foreach (MidValue midValue2 in item.WellCell.Well.Result.MidValues)
				{
					string key = "WellCell.Well.Result.MidValue" + midValue2.Name;
					if (!IsExist(list, key))
					{
						list.Add(new KeyValuePair
						{
							Key = key,
							Value = midValue2.Name
						});
					}
				}
				foreach (MidValue midValue3 in item.SampleTargetItem.Result.MidValues)
				{
					string key = "SampleTargetItem.Result.MidValue" + midValue3.Name;
					if (!IsExist(list, key))
					{
						list.Add(new KeyValuePair
						{
							Key = key,
							Value = midValue3.Name
						});
					}
				}
			}
			return list;
		}

		private bool IsExist(List<KeyValuePair> list, string key)
		{
			return list.Where((KeyValuePair s) => s.Key.ToString() == key).Count() > 0;
		}

		private int GetTmCount(bool all = false)
		{
			int num = 0;
			if (Targets.Count > 0 && Targets[0].SampleTargetItem.Result is MeltingTargetResult)
			{
				IEnumerable<ChartData> source = (all ? Targets : view.View.Cast<ChartData>());
				List<int> list = source.Select((ChartData s) => ((MeltingTargetResult)s.SampleTargetItem.Result).PeakValues.Count).ToList();
				num = ((list.Count > 0) ? list.Max() : 0);
			}
			if ((Experiment.Type == EProjectType.Melt || Experiment.Type == EProjectType.HRM) && num == 0)
			{
				num = 1;
			}
			return num;
		}

		protected virtual void InsertNewColumn(string key, int index, string header, bool visible)
		{
			UltraGridColumn ultraGridColumn = null;
			int num = ultraGrid.DisplayLayout.Bands[0].Columns.IndexOf(key);
			if (num >= 0)
			{
				ultraGridColumn = ultraGrid.DisplayLayout.Bands[0].Columns[num];
			}
			else
			{
				if (key == "SampleTargetItem.ChannelNo")
				{
					informationTable.Band.Columns.Add(key, typeof(int));
				}
				else if (IsDisplayNumberKey(key))
				{
					informationTable.Band.Columns.Add(key, typeof(double));
				}
				else
				{
					informationTable.Band.Columns.Add(key, typeof(string));
				}
				ultraGridColumn = ultraGrid.DisplayLayout.Bands[0].Columns[ultraGrid.DisplayLayout.Bands[0].Columns.Count - 1];
				ultraGridColumn.FilterClearButtonVisible = DefaultableBoolean.False;
				ultraGridColumn.MergedCellContentArea = MergedCellContentArea.VirtualRect;
				ultraGridColumn.MergedCellEvaluator = new CustomMergedCellEvaluator(view);
				ultraGridColumn.MergedCellEvaluationType = MergedCellEvaluationType.MergeSameValue;
				ultraGridColumn.MergedCellStyle = ((key.IndexOf("Well") != -1) ? MergedCellStyle.Always : MergedCellStyle.Never);
				ultraGridColumn.AllowRowFiltering = (shouldFilter ? DefaultableBoolean.True : DefaultableBoolean.False);
				string caption = header;
				if (key.IndexOf("SampleTargetItem.Result.Tm") == 0)
				{
					ultraGridColumn.Format = "#,0.00";
					ultraGridColumn.FormatInfo = numberFormatInfo;
				}
				else if (key.IndexOf("SampleTargetItem.Result.Rm") == 0)
				{
					ultraGridColumn.Format = "#,0.00";
					ultraGridColumn.FormatInfo = numberFormatInfo;
				}
				else if (key.IndexOf("SampleTargetItem.Result.Ym") == 0)
				{
					ultraGridColumn.Format = "#,0.000";
					ultraGridColumn.FormatInfo = numberFormatInfo;
				}
				else if (key.IndexOf("SampleTargetItem.Result.Wm") == 0)
				{
					ultraGridColumn.Format = "#,0.00";
					ultraGridColumn.FormatInfo = numberFormatInfo;
				}
				else if (key.IndexOf("SampleTargetItem.Result.MidValue") == 0)
				{
					caption = key.Replace("SampleTargetItem.Result.MidValue", "");
				}
				else if (key.IndexOf("WellCell.Well.Result.MidValue") == 0)
				{
					caption = key.Replace("WellCell.Well.Result.MidValue", "");
				}
				else if (key.IndexOf("WellCell.Well.Sample.Result.MidValue") == 0)
				{
					caption = key.Replace("WellCell.Well.Sample.Result.MidValue", "");
				}
				else
				{
					switch (key)
					{
					case "WellCell.Well.CellName":
						ultraGridColumn.Header.Fixed = !AutoWidth;
						ultraGridColumn.CellAppearance.TextHAlign = ((!AutoWidth) ? HAlign.Left : HAlign.Center);
						ultraGridColumn.LockedWidth = !AutoWidth;
						break;
					case "SampleTargetItem.ChannelNo":
						DisplayChannel(_ChannelDisplayInit, false, false);
						break;
					case "SampleTargetItem.LineColor":
						ultraGridColumn.AllowRowFiltering = DefaultableBoolean.False;
						ultraGridColumn.Style = Infragistics.Win.UltraWinGrid.ColumnStyle.FormattedText;
						break;
					case "SampleTargetItem.Result.CtValue":
						ultraGridColumn.Format = "#,0.00";
						ultraGridColumn.FormatInfo = numberFormatInfo;
						break;
					case "SampleTargetItem.Result.CtMean":
						ultraGridColumn.Format = "#,0.00";
						ultraGridColumn.FormatInfo = numberFormatInfo;
						break;
					case "SampleTargetItem.Result.CtSD":
						ultraGridColumn.Format = "#,0.00";
						ultraGridColumn.FormatInfo = numberFormatInfo;
						break;
					case "SampleTargetItem.Result.CtCV":
						ultraGridColumn.Format = "#,0.00";
						ultraGridColumn.FormatInfo = numberFormatInfo;
						break;
					case "SampleTargetItem.Result.CnValue":
						ultraGridColumn.SortComparer = new CustomCnValueComparer();
						ultraGridColumn.RowFilterComparer = new CustomCnValueComparer();
						break;
					case "SampleTargetItem.Result.CnMean":
						ultraGridColumn.Format = (UseScientific ? "0.000E0" : "#,0.00");
						ultraGridColumn.FormatInfo = numberFormatInfo;
						break;
					case "SampleTargetItem.Result.CnSD":
						ultraGridColumn.Format = (UseScientific ? "0.000E0" : "#,0.00");
						ultraGridColumn.FormatInfo = numberFormatInfo;
						break;
					case "SampleTargetItem.Result.CnCV":
						ultraGridColumn.Format = "#,0.00";
						ultraGridColumn.FormatInfo = numberFormatInfo;
						break;
					case "SampleTargetItem.Result.RnValue":
						ultraGridColumn.Format = "#,0.000";
						ultraGridColumn.FormatInfo = numberFormatInfo;
						break;
					case "SampleTargetItem.Result.QualityFactor":
						ultraGridColumn.Format = "#,0.00";
						ultraGridColumn.FormatInfo = numberFormatInfo;
						break;
					case "WellCell.Well.Result.QualityFactor":
						ultraGridColumn.Format = "#,0.00";
						ultraGridColumn.FormatInfo = numberFormatInfo;
						break;
					case "WellCell.Well.Sample.Result.ConclusionList":
					case "WellCell.Well.Result.ConclusionList":
					case "SampleTargetItem.Result.ConclusionList":
						ultraGridColumn.Style = Infragistics.Win.UltraWinGrid.ColumnStyle.FormattedText;
						break;
					}
				}
				ultraGridColumn.Header.Caption = caption;
			}
			ultraGridColumn.Header.VisiblePosition = index;
			ultraGridColumn.Hidden = !visible || IsNullColumn(key);
		}

		private bool IsNullColumn(string key)
		{
			bool flag = true;
			List<ChartData> source = view.View.Cast<ChartData>().ToList();
			if (GridColumns.NotDisplayNullColumn)
			{
				switch (key)
				{
				case "WellCell.Well.Sample.PatientInfo.ID":
					flag = flag && source.Where((ChartData s) => !string.IsNullOrEmpty(s.WellCell.Well.Sample.PatientInfo.ID)).Count() > 0;
					break;
				case "WellCell.Well.Sample.PatientInfo.Name":
					flag = flag && source.Where((ChartData s) => !string.IsNullOrEmpty(s.WellCell.Well.Sample.PatientInfo.Name)).Count() > 0;
					break;
				case "WellCell.Well.Sample.SampleName":
					flag = flag && source.Where((ChartData s) => !string.IsNullOrEmpty(s.WellCell.Well.Sample.SampleName)).Count() > 0;
					break;
				case "WellCell.Well.Sample.PatientInfo.Sex":
					flag = flag && source.Where((ChartData s) => !string.IsNullOrEmpty(s.WellCell.Well.Sample.PatientInfo.Sex)).Count() > 0;
					break;
				case "WellCell.Well.Sample.PatientInfo.Age":
					flag = flag && source.Where((ChartData s) => !string.IsNullOrEmpty(s.WellCell.Well.Sample.PatientInfo.Age)).Count() > 0;
					break;
				case "WellCell.Well.Sample.PatientInfo.Specimen":
					flag = flag && source.Where((ChartData s) => !string.IsNullOrEmpty(s.WellCell.Well.Sample.PatientInfo.Specimen)).Count() > 0;
					break;
				case "WellCell.Well.Sample.PatientInfo.SpecimenDate":
					flag = flag && source.Where((ChartData s) => !string.IsNullOrEmpty(s.WellCell.Well.Sample.PatientInfo.SpecimenDate)).Count() > 0;
					break;
				case "WellCell.Well.Sample.PatientInfo.Doctor":
					flag = flag && source.Where((ChartData s) => !string.IsNullOrEmpty(s.WellCell.Well.Sample.PatientInfo.Doctor)).Count() > 0;
					break;
				case "WellCell.Well.Sample.PatientInfo.Office":
					flag = flag && source.Where((ChartData s) => !string.IsNullOrEmpty(s.WellCell.Well.Sample.PatientInfo.Office)).Count() > 0;
					break;
				case "WellCell.Well.Sample.PatientInfo.Diagnosis":
					flag = flag && source.Where((ChartData s) => !string.IsNullOrEmpty(s.WellCell.Well.Sample.PatientInfo.Diagnosis)).Count() > 0;
					break;
				case "WellCell.Well.Sample.PatientInfo.CaseID":
					flag = flag && source.Where((ChartData s) => !string.IsNullOrEmpty(s.WellCell.Well.Sample.PatientInfo.CaseID)).Count() > 0;
					break;
				case "WellCell.Well.Sample.PatientInfo.BedID":
					flag = flag && source.Where((ChartData s) => !string.IsNullOrEmpty(s.WellCell.Well.Sample.PatientInfo.BedID)).Count() > 0;
					break;
				case "WellCell.Well.Sample.PatientInfo.InPatientID":
					flag = flag && source.Where((ChartData s) => !string.IsNullOrEmpty(s.WellCell.Well.Sample.PatientInfo.InPatientID)).Count() > 0;
					break;
				case "WellCell.Well.Sample.PatientInfo.OutPatientID":
					flag = flag && source.Where((ChartData s) => !string.IsNullOrEmpty(s.WellCell.Well.Sample.PatientInfo.OutPatientID)).Count() > 0;
					break;
				case "WellCell.Well.Sample.PatientInfo.Remark":
					flag = flag && source.Where((ChartData s) => !string.IsNullOrEmpty(s.WellCell.Well.Sample.PatientInfo.Remark)).Count() > 0;
					break;
				default:
					if (key.IndexOf("WellCell.Well.Sample.PatientInfoCustomData.") == 0)
					{
						int index = Convert.ToInt32(key.Replace("WellCell.Well.Sample.PatientInfoCustomData.", ""));
						flag = flag && source.Where((ChartData s) => index < s.WellCell.Well.Sample.PatientInfo.CustomData.Count && !string.IsNullOrEmpty(s.WellCell.Well.Sample.PatientInfo.CustomData[index])).Count() > 0;
						break;
					}
					switch (key)
					{
					case "WellCell.Well.TubeName":
						flag = flag && source.Where((ChartData s) => !string.IsNullOrEmpty(s.SampleTargetItem.TubeName)).Count() > 0;
						break;
					case "SampleTargetItem.Property":
						flag = flag && source.Where((ChartData s) => !string.IsNullOrEmpty(s.SampleTargetItem.Property)).Count() > 0;
						break;
					case "WellCell.Well.Sample.CompoundTubeNo":
						flag = flag && source.Where((ChartData s) => !string.IsNullOrEmpty(s.WellCell.Well.Sample.CompoundTubeNo)).Count() > 0;
						break;
					case "SampleTargetItem.Result.CtValue":
						flag = flag && source.Where((ChartData s) => !string.IsNullOrEmpty(ResultFormat.Format(s.SampleTargetItem.Result.CtValue))).Count() > 0;
						break;
					case "SampleTargetItem.Result.CtMean":
						flag = flag && source.Where((ChartData s) => !string.IsNullOrEmpty(ResultFormat.Format(s.SampleTargetItem.Result.CtMean))).Count() > 0;
						break;
					case "SampleTargetItem.Result.CtCV":
						flag = flag && source.Where((ChartData s) => !string.IsNullOrEmpty(ResultFormat.Format(s.SampleTargetItem.Result.CtCV))).Count() > 0;
						break;
					case "SampleTargetItem.Result.CtSD":
						flag = flag && source.Where((ChartData s) => !string.IsNullOrEmpty(ResultFormat.Format(s.SampleTargetItem.Result.CtSD))).Count() > 0;
						break;
					case "SampleTargetItem.Result.CnValue":
						flag = flag && source.Where((ChartData s) => !string.IsNullOrEmpty(ResultFormat.FormatCnValue(Subset, s.WellCell.Well, s.SampleTargetItem.ChannelNo, s.SampleTargetItem.Result.CnValue, string.Empty))).Count() > 0;
						break;
					case "SampleTargetItem.Result.CnMean":
						flag = flag && source.Where((ChartData s) => !string.IsNullOrEmpty(ResultFormat.Format(s.SampleTargetItem.Result.CnMean))).Count() > 0;
						break;
					case "SampleTargetItem.Result.CnCV":
						flag = flag && source.Where((ChartData s) => !string.IsNullOrEmpty(ResultFormat.Format(s.SampleTargetItem.Result.CnCV))).Count() > 0;
						break;
					case "SampleTargetItem.Result.CnSD":
						flag = flag && source.Where((ChartData s) => !string.IsNullOrEmpty(ResultFormat.Format(s.SampleTargetItem.Result.CnSD))).Count() > 0;
						break;
					case "SampleTargetItem.Result.RnValue":
						flag = flag && source.Where((ChartData s) => !string.IsNullOrEmpty(ResultFormat.Format(s.SampleTargetItem.Result.RnValue))).Count() > 0;
						break;
					case "SampleTargetItem.Result.QualityFactor":
						flag = flag && source.Where((ChartData s) => !string.IsNullOrEmpty(ResultFormat.Format(((MeltingTargetResult)s.SampleTargetItem.Result).QualityFactor, "#,0.00"))).Count() > 0;
						break;
					case "WellCell.Well.Result.QualityFactor":
						flag = flag && source.Where((ChartData s) => !string.IsNullOrEmpty(ResultFormat.Format(((ADWellResult)s.WellCell.Well.Result).QualityFactor, "#,0.00"))).Count() > 0;
						break;
					}
					break;
				}
			}
			switch (key)
			{
			case "WellCell.Well.Sample.Result.ConclusionList":
				flag = flag && source.Where((ChartData s) => s.WellCell.Well.Sample.Result.ConclusionList.Count > 0).Count() > 0;
				break;
			case "WellCell.Well.Result.ConclusionList":
				flag = flag && source.Where((ChartData s) => s.WellCell.Well.Result.ConclusionList.Count > 0).Count() > 0;
				break;
			case "SampleTargetItem.Result.ConclusionList":
				flag = flag && source.Where((ChartData s) => s.SampleTargetItem.Result.ConclusionList.Count > 0).Count() > 0;
				break;
			}
			return !flag;
		}

		private void informationTable_CellDataRequested(object sender, CellDataRequestedEventArgs e)
		{
			List<ChartData> list = view.View.Cast<ChartData>().ToList();
			if (e.Row.Index >= list.Count)
			{
				return;
			}
			ChartData chartData = list[e.Row.Index];
			e.Data = GetColumnData(e.Column.Key, chartData);
			if (e.Column.Index == 0)
			{
				UltraGridRow ultraGridRow = ultraGrid.Rows.Where((UltraGridRow s) => s.ListIndex == e.Row.Index).FirstOrDefault();
				if (RowSpaceMode == ERowSpaceMode.Null)
				{
					ultraGridRow.RowSpacingBefore = -1;
				}
				else
				{
					UltraGridRow sibling = ultraGridRow.GetSibling(SiblingRow.Previous, false);
					while (sibling != null && sibling.IsFilteredOut)
					{
						sibling = sibling.GetSibling(SiblingRow.Previous, false);
					}
					if (sibling == null)
					{
						ultraGridRow.RowSpacingBefore = -1;
					}
					else if ((RowSpaceMode == ERowSpaceMode.Well && list[ultraGridRow.ListIndex].WellCell.Well == list[sibling.ListIndex].WellCell.Well) || (RowSpaceMode == ERowSpaceMode.Sample && list[ultraGridRow.ListIndex].WellCell.Well.Sample == list[sibling.ListIndex].WellCell.Well.Sample))
					{
						ultraGridRow.RowSpacingBefore = -1;
					}
					else
					{
						ultraGridRow.RowSpacingBefore = 3;
					}
				}
			}
			e.CacheData = false;
		}

		private void ShowCellContent(UltraGridCell cell, bool visible = true)
		{
			if (cell != null)
			{
				if (visible)
				{
					cell.SelectedAppearance = null;
					cell.ActiveAppearance = null;
					cell.Appearance = null;
				}
				else
				{
					cell.SelectedAppearance.ForeColor = Color.Transparent;
					cell.ActiveAppearance.ForeColor = Color.Transparent;
					cell.Appearance.ForeColor = Color.Transparent;
				}
			}
		}

		protected string ConvertConclusionToHtml(Conclusion conclusion)
		{
			string arg = conclusion.Content.Replace("&", "&amp;").Replace("<", "&lt;").Replace(">", "&gt;");
			return string.Format("<span style=\"color: {0};\">{1}</span> ", conclusion.Color.ToString(), arg);
		}

		private void RefreshSelectedStyle()
		{
		}

		protected virtual void InitMenu()
		{
			System.Windows.Controls.MenuItem menuItem = null;
			menuItem = new System.Windows.Controls.MenuItem();
			menuItem.Header = Utility.GetMessage("copy_selected_data");
			menuItem.Click += itemCopyColumnData_Click;
			Menu.Items.Add(menuItem);
			menuItem = new System.Windows.Controls.MenuItem();
			menuItem.Header = Utility.GetMessage("export_selected_data");
			menuItem.Click += itemDataExport_Click;
			Menu.Items.Add(menuItem);
			menuItem = new System.Windows.Controls.MenuItem();
			menuItem.Header = Utility.GetMessage("print_selected_data");
			menuItem.Click += itemPrint_Click;
			Menu.Items.Add(menuItem);
			if (WellInfoType == EWellInfoType.Analysis)
			{
				Menu.Items.Add(new Separator());
				menuItem = new System.Windows.Controls.MenuItem();
				menuItem.Header = Utility.GetMessage("show_paramter");
				menuItem.IsCheckable = true;
				menuItem.SetBinding(System.Windows.Controls.MenuItem.IsCheckedProperty, new System.Windows.Data.Binding("ParamterVisible")
				{
					Source = Experiment.ExperimentSetting
				});
				Menu.Items.Add(menuItem);
				menuItem = new System.Windows.Controls.MenuItem();
				menuItem.Header = Utility.GetMessage("show_well_plate");
				menuItem.IsCheckable = true;
				menuItem.SetBinding(System.Windows.Controls.MenuItem.IsCheckedProperty, new System.Windows.Data.Binding("WellPlateVisible")
				{
					Source = Experiment.ExperimentSetting
				});
				Menu.Items.Add(menuItem);
			}
			Menu.Items.Add(new Separator());
			menuItem = new System.Windows.Controls.MenuItem();
			menuItem.Header = Utility.GetMessage("welldata_selected_mode");
			System.Windows.Controls.MenuItem menuItem2 = new System.Windows.Controls.MenuItem();
			menuItem2.Header = Utility.GetMessage("welldata_selected_mode_taget");
			menuItem2.IsCheckable = true;
			menuItem2.SetBinding(System.Windows.Controls.MenuItem.IsCheckedProperty, new System.Windows.Data.Binding("DataRowSelectMode")
			{
				Source = this,
				Converter = new EnumBooleanConverter(),
				ConverterParameter = "Target"
			});
			menuItem.Items.Add(menuItem2);
			menuItem2 = new System.Windows.Controls.MenuItem();
			menuItem2.Header = Utility.GetMessage("welldata_selected_mode_reaction");
			menuItem2.IsCheckable = true;
			menuItem2.SetBinding(System.Windows.Controls.MenuItem.IsCheckedProperty, new System.Windows.Data.Binding("DataRowSelectMode")
			{
				Source = this,
				Converter = new EnumBooleanConverter(),
				ConverterParameter = "Well"
			});
			menuItem.Items.Add(menuItem2);
			menuItem2 = new System.Windows.Controls.MenuItem();
			menuItem2.Header = Utility.GetMessage("welldata_selected_mode_sample");
			menuItem2.IsCheckable = true;
			menuItem2.SetBinding(System.Windows.Controls.MenuItem.IsCheckedProperty, new System.Windows.Data.Binding("DataRowSelectMode")
			{
				Source = this,
				Converter = new EnumBooleanConverter(),
				ConverterParameter = "Sample"
			});
			menuItem.Items.Add(menuItem2);
			menuItem2 = new System.Windows.Controls.MenuItem();
			menuItem2.Header = Utility.GetMessage("welldata_selected_mode_cell");
			menuItem2.IsCheckable = true;
			menuItem2.SetBinding(System.Windows.Controls.MenuItem.IsCheckedProperty, new System.Windows.Data.Binding("DataRowSelectMode")
			{
				Source = this,
				Converter = new EnumBooleanConverter(),
				ConverterParameter = "Cell"
			});
			menuItem.Items.Add(menuItem2);
			Menu.Items.Add(menuItem);
			Menu.Items.Add(new Separator());
			menuItem = new System.Windows.Controls.MenuItem();
			menuItem.Header = Utility.GetMessage("multi_sort");
			menuItem.Click += itemMultiSort_Click;
			Menu.Items.Add(menuItem);
			menuItem = new System.Windows.Controls.MenuItem();
			menuItem.Header = Utility.GetMessage("clear_sort_filter");
			menuItem.Click += itemClearSortFilter_Click;
			Menu.Items.Add(menuItem);
		}

		public void SetContextMenuDisable()
		{
			Menu = null;
		}

		private void itemCopyColumnData_Click(object sender, RoutedEventArgs e)
		{
			CopySelectedToClipBoard();
		}

		private void itemDataExport_Click(object sender, RoutedEventArgs e)
		{
			SaveFileDialog saveFileDialog = new SaveFileDialog();
			saveFileDialog.Title = Utility.GetMessage("Save");
			saveFileDialog.Filter = string.Format("{1}{0}|*.{2}|{3}{0}|*.{3}|{4}{0}|*.{4}", Utility.GetMessage("File"), "Excel", "xlsx", "csv", "txt");
			saveFileDialog.FilterIndex = 1;
			saveFileDialog.InitialDirectory = Utility.GetMyDocumentFolder();
			if (saveFileDialog.ShowDialog() == DialogResult.OK)
			{
				base.Cursor = System.Windows.Input.Cursors.Wait;
				switch (saveFileDialog.FilterIndex)
				{
				case 1:
					SaveSelectedDataToExcel(saveFileDialog.FileName);
					break;
				case 2:
				case 3:
					SaveSelectedDataToCsv(saveFileDialog.FileName);
					break;
				}
				base.Cursor = System.Windows.Input.Cursors.Arrow;
				System.Windows.MessageBox.Show(Utility.GetMessage("msg_data_export_sussess"));
			}
		}

		private void itemPrint_Click(object sender, RoutedEventArgs e)
		{
			string systemTempFile = Utility.GetSystemTempFile();
			string text = systemTempFile + ".xlsx";
			SaveSelectedDataToExcel(text);
			ExcelOperator.PrintExcel(text, true);
		}

		public void SortView(string key)
		{
			ultraGrid.DisplayLayout.Bands[0].SortedColumns.Clear();
			if (!key.Equals(string.Empty))
			{
				ultraGrid.DisplayLayout.Bands[0].SortedColumns.Add(key, false);
			}
		}

		private void itemMultiSort_Click(object sender, RoutedEventArgs e)
		{
			MultiSortWindow multiSortWindow = new MultiSortWindow();
			multiSortWindow.Owner = Utility.GetMainWindow();
			List<UltraGridColumn> list = (from UltraGridColumn s in ultraGrid.DisplayLayout.Bands[0].Columns
				where !s.Hidden && s.Key != "WellCell.Well.CellName" && s.Key != "SampleTargetItem.LineColor"
				orderby s.Header.VisiblePosition
				select s).ToList();
			List<KeyValuePair> list2 = new List<KeyValuePair>();
			list2.Add(new KeyValuePair());
			foreach (UltraGridColumn item in list)
			{
				list2.Add(new KeyValuePair
				{
					Key = item.Key,
					Value = item.Header.Caption
				});
			}
			multiSortWindow.HeaderList = list2;
			if (ultraGrid.DisplayLayout.Bands[0].SortedColumns.Count > 0)
			{
				multiSortWindow.FirstSortKey = ultraGrid.DisplayLayout.Bands[0].SortedColumns[0].Key;
				multiSortWindow.FirstSortIsAscending = ultraGrid.DisplayLayout.Bands[0].SortedColumns[0].SortIndicator == SortIndicator.Ascending;
			}
			else
			{
				multiSortWindow.FirstSortIsAscending = true;
			}
			if (ultraGrid.DisplayLayout.Bands[0].SortedColumns.Count > 1)
			{
				multiSortWindow.SecondSortKey = ultraGrid.DisplayLayout.Bands[0].SortedColumns[1].Key;
				multiSortWindow.SecondSortIsAscending = ultraGrid.DisplayLayout.Bands[0].SortedColumns[1].SortIndicator == SortIndicator.Ascending;
			}
			else
			{
				multiSortWindow.SecondSortIsAscending = true;
			}
			if (ultraGrid.DisplayLayout.Bands[0].SortedColumns.Count > 2)
			{
				multiSortWindow.ThirdSortKey = ultraGrid.DisplayLayout.Bands[0].SortedColumns[2].Key;
				multiSortWindow.ThirdSortIsAscending = ultraGrid.DisplayLayout.Bands[0].SortedColumns[2].SortIndicator == SortIndicator.Ascending;
			}
			else
			{
				multiSortWindow.ThirdSortIsAscending = true;
			}
			if (multiSortWindow.ShowDialog() == true)
			{
				ultraGrid.DisplayLayout.Bands[0].SortedColumns.Clear();
				if (!string.IsNullOrEmpty(multiSortWindow.FirstSortKey))
				{
					ultraGrid.DisplayLayout.Bands[0].SortedColumns.Add(multiSortWindow.FirstSortKey, !multiSortWindow.FirstSortIsAscending);
				}
				if (!string.IsNullOrEmpty(multiSortWindow.SecondSortKey))
				{
					ultraGrid.DisplayLayout.Bands[0].SortedColumns.Add(multiSortWindow.SecondSortKey, !multiSortWindow.SecondSortIsAscending);
				}
				if (!string.IsNullOrEmpty(multiSortWindow.ThirdSortKey))
				{
					ultraGrid.DisplayLayout.Bands[0].SortedColumns.Add(multiSortWindow.ThirdSortKey, !multiSortWindow.ThirdSortIsAscending);
				}
				if (!string.IsNullOrEmpty(multiSortWindow.FirstSortKey) || !string.IsNullOrEmpty(multiSortWindow.SecondSortKey) || !string.IsNullOrEmpty(multiSortWindow.ThirdSortKey))
				{
					_CustomSort = true;
					RefreshSortMode();
				}
				else
				{
					_CustomSort = false;
					SampleSortMode = Experiment.ExperimentSetting.SampleSortMode;
				}
			}
		}

		private void itemClearSortFilter_Click(object sender, RoutedEventArgs e)
		{
			ultraGrid.DisplayLayout.Bands[0].ColumnFilters.ClearAllFilters();
			if (ultraGrid.DisplayLayout.Bands[0].SortedColumns.Count > 0)
			{
				ultraGrid.DisplayLayout.Bands[0].SortedColumns.Clear();
			}
			_CustomSort = false;
			RefreshSortMode();
			RaiseChannelNoChangedEvent();
			RaiseSelectionChanged();
		}

		private void SetHightChartData(ChartData chartData)
		{
			if (HighLight && (highLightChartData == null || highLightChartData != chartData))
			{
				if (highLightChartData != null)
				{
					highLightChartData.HighLight = false;
					highLightChartData.WellCell.HighLight = false;
				}
				if (chartData != null)
				{
					chartData.HighLight = true;
					chartData.WellCell.HighLight = true;
				}
				highLightChartData = chartData;
			}
		}

		private void RefreshHightRow(int x, int y)
		{
			if (!HighLight)
			{
				return;
			}
			System.Drawing.Point point = new System.Drawing.Point(x, y);
			Infragistics.Win.UIElement uIElement = ultraGrid.DisplayLayout.UIElement.ElementFromPoint(point);
			if (uIElement == null || uIElement is HeaderUIElement)
			{
				SetHightChartData(null);
				return;
			}
			UltraGridCell ultraGridCell = uIElement.GetContext(typeof(UltraGridCell)) as UltraGridCell;
			if (ultraGridCell != null)
			{
				List<ChartData> list = view.View.Cast<ChartData>().ToList();
				if (ultraGridCell.Row.ListIndex >= 0 && ultraGridCell.Row.ListIndex < list.Count)
				{
					SetHightChartData(list[ultraGridCell.Row.ListIndex]);
				}
			}
			else
			{
				SetHightChartData(null);
			}
		}

		private void RaiseChannelNoChangedEvent()
		{
			if (WellInfoType == EWellInfoType.Edit)
			{
				return;
			}
			ColumnFilter columnFilter = (from ColumnFilter s in ultraGrid.DisplayLayout.Bands[0].ColumnFilters
				where s.Column.Key == "SampleTargetItem.ChannelNo"
				select s).FirstOrDefault();
			if (columnFilter == null)
			{
				return;
			}
			ChannelNoChangedRoutedEventArgs channelNoChangedRoutedEventArgs = new ChannelNoChangedRoutedEventArgs();
			channelNoChangedRoutedEventArgs.RoutedEvent = OnChannelNoChangedRoutedEvent;
			ChannelNoChangedRoutedEventArgs channelNoChangedRoutedEventArgs2 = channelNoChangedRoutedEventArgs;
			if (columnFilter.FilterConditions.Count == 0)
			{
				channelNoChangedRoutedEventArgs2.ChannelDisplay = new bool[6] { true, true, true, true, true, true };
			}
			else
			{
				bool[] channelDisplay = new bool[6];
				channelNoChangedRoutedEventArgs2.ChannelDisplay = channelDisplay;
				foreach (FilterCondition item in (IEnumerable)columnFilter.FilterConditions)
				{
					if (item.CompareValue is int)
					{
						channelNoChangedRoutedEventArgs2.ChannelDisplay[Convert.ToInt32(item.CompareValue) - 1] = true;
					}
				}
			}
			RaiseEvent(channelNoChangedRoutedEventArgs2);
		}

		private void ultraGrid_AfterSelectChange(object sender, AfterSelectChangeEventArgs e)
		{
			RefreshSelectedStyle();
		}

		private void ultraGrid_AfterRowFilterChanged(object sender, AfterRowFilterChangedEventArgs e)
		{
			RaiseChannelNoChangedEvent();
			RefreshDataRowSelected();
			RaiseSelectionChanged();
		}

		private void ultraGrid_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if (e.Control && e.KeyCode == Keys.C)
			{
				CopySelectedToClipBoard();
			}
		}

		private void ultraGrid_Click(object sender, EventArgs e)
		{
			Infragistics.Win.UIElement uIElement = ultraGrid.DisplayLayout.UIElement;
			System.Drawing.Point point = ultraGrid.PointToClient(System.Windows.Forms.Control.MousePosition);
			Infragistics.Win.UIElement uIElement2 = uIElement.ElementFromPoint(point);
			if (uIElement2 != null)
			{
				uIElement2 = uIElement2.GetAncestor(typeof(RowSelectorHeaderUIElement));
			}
			if (uIElement2 != null)
			{
				SelectAllGridData();
			}
		}

		private void ultraGrid_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
		{
			if (!_IsMouseDown)
			{
				RefreshHightRow(e.X, e.Y);
			}
		}

		private void ultraGrid_MouseLeave(object sender, EventArgs e)
		{
			SetHightChartData(null);
		}

		private void ultraGrid_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
		{
			_IsMouseDown = true;
			SetHightChartData(null);
		}

		private void ultraGrid_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
		{
			_IsMouseDown = false;
			if (view.View != null && e.Button == MouseButtons.Left)
			{
				RefreshDataRowSelected();
				RaiseSelectionChanged();
			}
			if (e.Button == MouseButtons.Right && Menu != null)
			{
				((System.Windows.Controls.MenuItem)Menu.Items[0]).IsEnabled = ultraGrid.Selected.Cells.Count > 0 || ultraGrid.Selected.Columns.Count > 0 || ultraGrid.Selected.Rows.Count > 0;
				Menu.Placement = PlacementMode.MousePoint;
				Menu.IsOpen = true;
			}
		}

		private void ultraGrid_MouseWheel(object sender, System.Windows.Forms.MouseEventArgs e)
		{
			if ((Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control)
			{
				ultraGrid.Font = new Font(ultraGrid.Font.Name, Math.Min(Math.Max(ultraGrid.Font.Size + (float)(e.Delta / 120), 6f), 20f));
				AutoSizeColumnSize();
			}
			RefreshHightRow(e.X, e.Y);
		}

		private void ultraGrid_BeforeRowResize(object sender, BeforeRowResizeEventArgs e)
		{
			if (e.NewHeight > 70)
			{
				e.Cancel = true;
			}
		}

		private void ultraGrid_InitializeLayout(object sender, InitializeLayoutEventArgs e)
		{
			e.Layout.Override.CellPadding = 2;
			ultraGrid.DisplayLayout.UseFixedHeaders = true;
			e.Layout.Override.DefaultRowHeight = 20;
			e.Layout.Override.CellMultiLine = DefaultableBoolean.True;
			e.Layout.Override.FixedHeaderIndicator = FixedHeaderIndicator.None;
			e.Layout.Override.HeaderAppearance.TextHAlign = HAlign.Center;
			e.Layout.Override.HeaderAppearance.TextVAlign = VAlign.Middle;
			e.Layout.Override.HeaderAppearance.BackColor = Utility.GetDrawingColor("ColorDataGridHeadDown");
			e.Layout.Override.HeaderAppearance.BackColor2 = Utility.GetDrawingColor("ColorDataGridHeadUp");
			e.Layout.Override.HeaderAppearance.BackGradientStyle = GradientStyle.Vertical;
			e.Layout.Override.CellAppearance.TextHAlign = HAlign.Center;
			e.Layout.Override.CellAppearance.TextVAlign = VAlign.Top;
			RefreshDataRowSelectMode();
			e.Layout.Override.MergedCellAppearance.TextHAlign = HAlign.Center;
			e.Layout.Override.MergedCellAppearance.TextVAlign = VAlign.Top;
			e.Layout.Override.RowSelectors = DefaultableBoolean.True;
			e.Layout.Override.RowSelectorWidth = 35;
			e.Layout.Override.RowSelectorNumberStyle = RowSelectorNumberStyle.VisibleIndex;
			e.Layout.Override.RowSelectorAppearance.TextHAlign = HAlign.Center;
			e.Layout.Override.RowSelectorAppearance.TextVAlign = VAlign.Middle;
			e.Layout.Override.RowSelectorHeaderStyle = RowSelectorHeaderStyle.SeparateElement;
			e.Layout.Override.RowSelectorAppearance.BackColor = Utility.GetDrawingColor("ColorWellPlateLeft");
			e.Layout.Override.RowSelectorAppearance.BackGradientStyle = GradientStyle.None;
			e.Layout.Override.CellAppearance.TextTrimming = Infragistics.Win.TextTrimming.None;
			e.Layout.Override.SelectedRowAppearance.BackColor = Utility.GetDrawingColor("ColorDataGridCellSelect");
			e.Layout.Override.SelectedRowAppearance.ForeColor = Color.Black;
			e.Layout.Override.ActiveRowAppearance = null;
			e.Layout.Override.RowSizing = RowSizing.Fixed;
			e.Layout.Override.HeaderClickAction = HeaderClickAction.Select;
			e.Layout.Override.AllowColMoving = AllowColMoving.NotAllowed;
			e.Layout.ScrollBounds = ScrollBounds.ScrollToFill;
			e.Layout.ScrollStyle = ScrollStyle.Immediate;
		}

		public List<KeyValuePair> GetColumnHeader(bool allData = false)
		{
			List<KeyValuePair> list = new List<KeyValuePair>();
			foreach (UltraGridColumn column in ultraGrid.DisplayLayout.Bands[0].Columns)
			{
				string key = column.Key;
				if (ConfigSettings.GetInstance().BasicSetting.Customer == 1)
				{
					switch (key)
					{
					case "WellCell.Well.Result.ConclusionList":
						list.Insert(list.Count - 1, new KeyValuePair
						{
							Value = column.Header.Caption,
							Key = key
						});
						continue;
					case "WellCell.Well.Sample.Result.ConclusionList":
						list.Insert(list.Count - 2, new KeyValuePair
						{
							Value = column.Header.Caption,
							Key = key
						});
						continue;
					case "WellCell.Well.Sample.SampleName":
						continue;
					}
				}
				if (allData)
				{
					if (key.IndexOf("SampleTargetItem.Result.Tm") == 0 || key.IndexOf("SampleTargetItem.Result.Rm") == 0 || key.IndexOf("SampleTargetItem.Result.Ym") == 0 || key.IndexOf("SampleTargetItem.Result.Wm") == 0 || key.IndexOf("WellCell.Well.Sample.Result.MidValue") == 0 || key.IndexOf("WellCell.Well.Result.MidValue") == 0 || key.IndexOf("SampleTargetItem.Result.MidValue") == 0)
					{
						continue;
					}
					if (key.IndexOf("SampleTargetItem.Result.ConclusionList") == 0)
					{
						int tmCount = GetTmCount(true);
						for (int i = 0; i < tmCount; i++)
						{
							list.Add(new KeyValuePair
							{
								Value = Utility.GetMessage("Tm") + (i + 1),
								Key = "SampleTargetItem.Result.Tm" + i
							});
							list.Add(new KeyValuePair
							{
								Value = Utility.GetMessage("Rm") + (i + 1),
								Key = "SampleTargetItem.Result.Rm" + i
							});
							list.Add(new KeyValuePair
							{
								Value = Utility.GetMessage("Ym") + (i + 1),
								Key = "SampleTargetItem.Result.Ym" + i
							});
							if ((from UltraGridColumn s in ultraGrid.DisplayLayout.Bands[0].Columns
								where s.Key.IndexOf("SampleTargetItem.Result.Wm") == 0
								select s).FirstOrDefault() != null)
							{
								list.Add(new KeyValuePair
								{
									Value = Utility.GetMessage("Wm") + (i + 1),
									Key = "SampleTargetItem.Result.Wm" + i
								});
							}
						}
						List<KeyValuePair> midValue = GetMidValue(true);
						foreach (KeyValuePair item in midValue)
						{
							list.Add(item);
						}
					}
					if (key.IndexOf("WellCell.Well.TubeName") == 0)
					{
						list.Add(new KeyValuePair
						{
							Value = Utility.GetMessage("tube_no"),
							Key = "WellCell.Well.TubeNo"
						});
					}
				}
				else if (column.Hidden)
				{
					continue;
				}
				list.Add(new KeyValuePair
				{
					Value = column.Header.Caption,
					Key = key
				});
			}
			return list;
		}

		public List<List<string>> GetBasicData(List<ChartData> datas, bool includeMergerCellInfo = false)
		{
			List<List<string>> list = new List<List<string>>();
			if (includeMergerCellInfo)
			{
				list.Add(new List<string>
				{
					null,
					string.Empty
				});
			}
			list.Add(new List<string>
			{
				Utility.GetMessage("reaction_well"),
				Utility.GetMessage("Channel")
			});
			WellCell wellCell = null;
			foreach (ChartData data in datas)
			{
				if (includeMergerCellInfo)
				{
					if (wellCell != data.WellCell)
					{
						list.Add(new List<string>
						{
							data.WellCell.Well.CellName,
							data.SampleTargetItem.ChannelNo.ToString()
						});
					}
					else
					{
						list.Add(new List<string>
						{
							string.Empty,
							data.SampleTargetItem.ChannelNo.ToString()
						});
					}
				}
				else
				{
					list.Add(new List<string>
					{
						data.WellCell.Well.CellName,
						data.SampleTargetItem.ChannelNo.ToString()
					});
				}
				wellCell = data.WellCell;
			}
			return list;
		}

		public List<ChartData> GetCurrentTargets()
		{
			List<ChartData> list = view.View.Cast<ChartData>().ToList();
			List<ChartData> list2 = new List<ChartData>();
			foreach (UltraGridRow item in ultraGrid.Rows.Where((UltraGridRow s) => !s.IsFilteredOut))
			{
				list2.Add(list[item.ListIndex]);
			}
			return list2;
		}

		public List<ChartData> GetSortedTargets()
		{
			IOrderedEnumerable<ChartData> orderedEnumerable = null;
			switch (SampleSortMode)
			{
			case ESampleSortMode.Column:
				orderedEnumerable = Targets.OrderBy((ChartData s) => s.WellCell.Well.Sample.Wells[0].ColumnIndex);
				break;
			case ESampleSortMode.Row:
				orderedEnumerable = Targets.OrderBy((ChartData s) => s.WellCell.Well.Sample.Wells[0].RowIndex);
				break;
			case ESampleSortMode.Module:
				orderedEnumerable = from s in Targets
					orderby s.WellCell.Well.Sample.Wells[0].ModelA, s.WellCell.Well.Sample.Wells[0].RowIndex
					select s;
				break;
			}
			if (orderedEnumerable == null)
			{
				return Targets.ToList();
			}
			orderedEnumerable = orderedEnumerable.ThenBy((ChartData s) => s.WellCell.Well.Sample).ThenBy((ChartData s) => s.WellCell.Well.MultiTubeID).ThenBy((ChartData s) => s.SampleTargetItem.ChannelNo);
			return orderedEnumerable.ToList();
		}

		public List<List<string>> GetData(List<ChartData> datas, bool allData = false, bool includeMergerCellInfo = false)
		{
			List<List<string>> list = new List<List<string>>();
			List<KeyValuePair> columnHeader = GetColumnHeader(allData);
			list.Add(columnHeader.Select((KeyValuePair s) => s.Value.ToString()).ToList());
			List<string> list2 = new List<string>();
			foreach (KeyValuePair item in columnHeader)
			{
				KeyValuePair keyValuePair = item;
				list2.Add(string.Empty);
			}
			if (includeMergerCellInfo)
			{
				list.Insert(0, list2);
			}
			List<ChartData> list3 = null;
			if (datas != null)
			{
				list3 = datas;
			}
			else
			{
				list3 = new List<ChartData>();
				List<ChartData> list4 = view.View.Cast<ChartData>().ToList();
				foreach (UltraGridRow row in ultraGrid.Selected.Rows)
				{
					list3.Add(list4[row.ListIndex]);
				}
			}
			for (int i = 0; i < list3.Count; i++)
			{
				ChartData chartData = list3[i];
				SampleTargetItem sampleTargetItem = chartData.SampleTargetItem;
				List<string> list5 = new List<string>();
				for (int j = 0; j < list2.Count; j++)
				{
					string key = columnHeader[j].Key.ToString();
					if (list2[j] == null && i > 0 && chartData.WellCell == list3[i - 1].WellCell)
					{
						list5.Add(string.Empty);
						continue;
					}
					object columnData = GetColumnData(key, chartData, false);
					list5.Add((columnData == null) ? string.Empty : columnData.ToString());
				}
				list.Add(list5);
			}
			return list;
		}

		protected virtual object GetColumnData(string key, ChartData chartData, bool displayData = true)
		{
			if (key.IndexOf("SampleTargetItem.Result.Tm") == 0)
			{
				int num = Convert.ToInt32(key.Replace("SampleTargetItem.Result.Tm", ""));
				MeltingTargetResult meltingTargetResult = chartData.SampleTargetItem.Result as MeltingTargetResult;
				if (displayData)
				{
					return (meltingTargetResult.PeakValues.Count > num) ? meltingTargetResult.PeakValues[num].Tm : double.NaN;
				}
				if (meltingTargetResult.PeakValues.Count <= num)
				{
					return string.Empty;
				}
				return ResultFormat.Format(meltingTargetResult.PeakValues[num].Tm, "0.00");
			}
			if (key.IndexOf("SampleTargetItem.Result.Rm") == 0)
			{
				int num2 = Convert.ToInt32(key.Replace("SampleTargetItem.Result.Rm", ""));
				MeltingTargetResult meltingTargetResult2 = chartData.SampleTargetItem.Result as MeltingTargetResult;
				if (displayData)
				{
					return (meltingTargetResult2.PeakValues.Count > num2) ? meltingTargetResult2.PeakValues[num2].Rm : double.NaN;
				}
				if (meltingTargetResult2.PeakValues.Count <= num2)
				{
					return string.Empty;
				}
				return ResultFormat.Format(meltingTargetResult2.PeakValues[num2].Rm, "0.00");
			}
			if (key.IndexOf("SampleTargetItem.Result.Ym") == 0)
			{
				int num3 = Convert.ToInt32(key.Replace("SampleTargetItem.Result.Ym", ""));
				MeltingTargetResult meltingTargetResult3 = chartData.SampleTargetItem.Result as MeltingTargetResult;
				if (displayData)
				{
					return (meltingTargetResult3.PeakValues.Count > num3) ? meltingTargetResult3.PeakValues[num3].YValue : double.NaN;
				}
				if (meltingTargetResult3.PeakValues.Count <= num3)
				{
					return string.Empty;
				}
				return ResultFormat.Format(meltingTargetResult3.PeakValues[num3].YValue, "0.00");
			}
			if (key.IndexOf("SampleTargetItem.Result.Wm") == 0)
			{
				int num4 = Convert.ToInt32(key.Replace("SampleTargetItem.Result.Wm", ""));
				MeltingTargetResult meltingTargetResult4 = chartData.SampleTargetItem.Result as MeltingTargetResult;
				if (displayData)
				{
					return (meltingTargetResult4.PeakValues.Count > num4) ? meltingTargetResult4.PeakValues[num4].Width : double.NaN;
				}
				if (meltingTargetResult4.PeakValues.Count <= num4)
				{
					return string.Empty;
				}
				return ResultFormat.Format(meltingTargetResult4.PeakValues[num4].Width, "0.00");
			}
			if (key.IndexOf("WellCell.Well.Sample.Result.MidValue") == 0)
			{
				string htKey = key.Replace("WellCell.Well.Sample.Result.MidValue", "");
				MidValue midValue = chartData.WellCell.Well.Sample.Result.MidValues.Where((MidValue s) => s.Name == htKey).FirstOrDefault();
				if (midValue != null)
				{
					return midValue.Value;
				}
			}
			else if (key.IndexOf("WellCell.Well.Result.MidValue") == 0)
			{
				string htKey2 = key.Replace("WellCell.Well.Result.MidValue", "");
				MidValue midValue2 = chartData.WellCell.Well.Result.MidValues.Where((MidValue s) => s.Name == htKey2).FirstOrDefault();
				if (midValue2 != null)
				{
					return midValue2.Value;
				}
			}
			else if (key.IndexOf("SampleTargetItem.Result.MidValue") == 0)
			{
				string htKey3 = key.Replace("SampleTargetItem.Result.MidValue", "");
				MidValue midValue3 = chartData.SampleTargetItem.Result.MidValues.Where((MidValue s) => s.Name == htKey3).FirstOrDefault();
				if (midValue3 != null)
				{
					return midValue3.Value;
				}
			}
			else
			{
				switch (key)
				{
				case "WellCell.Well.Sample.PatientInfo.ID":
					return chartData.WellCell.Well.Sample.PatientInfo.ID;
				case "WellCell.Well.Sample.PatientInfo.Name":
					return chartData.WellCell.Well.Sample.PatientInfo.Name;
				case "WellCell.Well.Sample.SampleName":
					return chartData.WellCell.Well.Sample.SampleName;
				case "WellCell.Well.Sample.PatientInfo.Sex":
					return chartData.WellCell.Well.Sample.PatientInfo.Sex;
				case "WellCell.Well.Sample.PatientInfo.Age":
					return chartData.WellCell.Well.Sample.PatientInfo.Age;
				case "WellCell.Well.Sample.PatientInfo.Specimen":
					return chartData.WellCell.Well.Sample.PatientInfo.Specimen;
				case "WellCell.Well.Sample.PatientInfo.SpecimenDate":
					return chartData.WellCell.Well.Sample.PatientInfo.SpecimenDate;
				case "WellCell.Well.Sample.PatientInfo.Doctor":
					return chartData.WellCell.Well.Sample.PatientInfo.Doctor;
				case "WellCell.Well.Sample.PatientInfo.Office":
					return chartData.WellCell.Well.Sample.PatientInfo.Office;
				case "WellCell.Well.Sample.PatientInfo.Diagnosis":
					return chartData.WellCell.Well.Sample.PatientInfo.Diagnosis;
				case "WellCell.Well.Sample.PatientInfo.CaseID":
					return chartData.WellCell.Well.Sample.PatientInfo.CaseID;
				case "WellCell.Well.Sample.PatientInfo.BedID":
					return chartData.WellCell.Well.Sample.PatientInfo.BedID;
				case "WellCell.Well.Sample.PatientInfo.InPatientID":
					return chartData.WellCell.Well.Sample.PatientInfo.InPatientID;
				case "WellCell.Well.Sample.PatientInfo.OutPatientID":
					return chartData.WellCell.Well.Sample.PatientInfo.OutPatientID;
				case "WellCell.Well.Sample.PatientInfo.Remark":
					return chartData.WellCell.Well.Sample.PatientInfo.Remark;
				}
				if (key.IndexOf("WellCell.Well.Sample.PatientInfoCustomData.") == 0)
				{
					int num5 = Convert.ToInt32(key.Replace("WellCell.Well.Sample.PatientInfoCustomData.", ""));
					if (num5 < chartData.WellCell.Well.Sample.PatientInfo.CustomData.Count)
					{
						return chartData.WellCell.Well.Sample.PatientInfo.CustomData[num5];
					}
				}
				else
				{
					switch (key)
					{
					case "WellCell.Well.CellName":
					{
						string text = chartData.WellCell.Well.CellName;
						if (!AutoWidth && displayData)
						{
							for (int i = 0; i < 5; i++)
							{
								text = " " + text;
							}
						}
						return text;
					}
					case "WellCell.Well.Project.BasicInfo.Name":
						return chartData.WellCell.Well.Project.BasicInfo.Name;
					case "WellCell.Well.TubeName":
						return chartData.SampleTargetItem.TubeName;
					case "WellCell.Well.TubeNo":
						return chartData.SampleTargetItem.TubeNo;
					case "SampleTargetItem.ChannelNo":
						return chartData.SampleTargetItem.ChannelNo;
					case "SampleTargetItem.Dye":
						return chartData.SampleTargetItem.Dye;
					case "SampleTargetItem.TargetName":
						return chartData.SampleTargetItem.TargetName;
					case "SampleTargetItem.LineColor":
						if (displayData)
						{
							return string.Format("<span style=\"background-color: {0};\">&nbsp;&nbsp;&nbsp;</span> ", chartData.GetChartDataColor(ColorMode).ToString());
						}
						return chartData.GetChartDataColor(ColorMode).ToString();
					case "SampleTargetItem.SampleType":
						return EnumManagement.GetSampleTypeName(chartData.SampleTargetItem.SampleType);
					case "SampleTargetItem.Property":
						if (chartData.SampleTargetItem.SampleType == SampleType.Standard)
						{
							double result = double.NaN;
							if (double.TryParse(chartData.SampleTargetItem.Property, out result))
							{
								return ResultFormat.Format(result, UseScientific ? "0.000E0" : "#,0.##");
							}
							return chartData.SampleTargetItem.Property;
						}
						return chartData.SampleTargetItem.Property;
					case "WellCell.Well.Sample.CompoundTubeNo":
						return chartData.WellCell.Well.Sample.CompoundTubeNo;
					case "SampleTargetItem.Result.CtValue":
						if (displayData)
						{
							return chartData.SampleTargetItem.Result.CtValue;
						}
						return ResultFormat.Format(chartData.SampleTargetItem.Result.CtValue, "0.00");
					case "SampleTargetItem.Result.CtMean":
						if (displayData)
						{
							return chartData.SampleTargetItem.Result.CtMean;
						}
						return ResultFormat.Format(chartData.SampleTargetItem.Result.CtMean, "0.00");
					case "SampleTargetItem.Result.CtSD":
						if (displayData)
						{
							return chartData.SampleTargetItem.Result.CtSD;
						}
						return ResultFormat.Format(chartData.SampleTargetItem.Result.CtSD, "0.00");
					case "SampleTargetItem.Result.CtCV":
						if (displayData)
						{
							return chartData.SampleTargetItem.Result.CtCV;
						}
						return ResultFormat.Format(chartData.SampleTargetItem.Result.CtCV, "0.00");
					case "SampleTargetItem.Result.CnValue":
						return ResultFormat.FormatCnValue(Subset, chartData.WellCell.Well, chartData.SampleTargetItem.ChannelNo, chartData.SampleTargetItem.Result.CnValue, UseScientific ? "0.000E0" : "#,0.00");
					case "SampleTargetItem.Result.CnMean":
						if (displayData)
						{
							return chartData.SampleTargetItem.Result.CnMean;
						}
						return ResultFormat.Format(chartData.SampleTargetItem.Result.CnMean, UseScientific ? "0.000E0" : "#,0.00");
					case "SampleTargetItem.Result.CnSD":
						if (displayData)
						{
							return chartData.SampleTargetItem.Result.CnSD;
						}
						return ResultFormat.Format(chartData.SampleTargetItem.Result.CnSD, UseScientific ? "0.000E0" : "#,0.00");
					case "SampleTargetItem.Result.CnCV":
						if (displayData)
						{
							return chartData.SampleTargetItem.Result.CnCV;
						}
						return ResultFormat.Format(chartData.SampleTargetItem.Result.CnCV, "0.00");
					case "SampleTargetItem.Result.RnValue":
						if (displayData)
						{
							return chartData.SampleTargetItem.Result.RnValue;
						}
						return ResultFormat.Format(chartData.SampleTargetItem.Result.RnValue, "0.000");
					case "SampleTargetItem.Result.Geno":
					{
						Subset.SubsetParamter subsetParamter = Experiment.CurrentSubset.GetSubsetParamter(chartData.WellCell.Well.Project);
						if (subsetParamter == null)
						{
							break;
						}
						HRMOptionItem hRMOptionItem = subsetParamter.BasicOption.Items.Where((BasicOptionItem s) => s.TargetName == chartData.SampleTargetItem.TargetName).FirstOrDefault() as HRMOptionItem;
						if (hRMOptionItem == null)
						{
							break;
						}
						if (hRMOptionItem.TypeMethod == EHRMTypeMethod.Auto)
						{
							return Experiment.CurrentSubset.GenoTypeList.Where((KeyValuePair s) => (EGenoType)s.Key == ((HRMTargetResult)chartData.SampleTargetItem.Result).GenoType).FirstOrDefault().Value;
						}
						return ((HRMTargetResult)chartData.SampleTargetItem.Result).GenoName;
					}
					case "SampleTargetItem.Result.QualityFactor":
						if (displayData)
						{
							return ((MeltingTargetResult)chartData.SampleTargetItem.Result).QualityFactor;
						}
						return ResultFormat.Format(((MeltingTargetResult)chartData.SampleTargetItem.Result).QualityFactor, "0.00");
					case "WellCell.Well.Result.TypeNo":
						return ((ADWellResult)chartData.WellCell.Well.Result).TypeName;
					case "WellCell.Well.Result.QualityFactor":
						if (displayData)
						{
							return ((ADWellResult)chartData.WellCell.Well.Result).QualityFactor;
						}
						return ResultFormat.Format(((ADWellResult)chartData.WellCell.Well.Result).QualityFactor, "0.00");
					case "WellCell.Well.Sample.Result.ConclusionList":
					{
						StringBuilder stringBuilder = new StringBuilder();
						foreach (Conclusion conclusion in chartData.WellCell.Well.Sample.Result.ConclusionList)
						{
							stringBuilder.Append(displayData ? ConvertConclusionToHtml(conclusion) : (conclusion.Content + " "));
						}
						if (!displayData && stringBuilder.Length > 0)
						{
							stringBuilder.Remove(stringBuilder.ToString().Length - 1, 1);
						}
						return stringBuilder.ToString();
					}
					case "WellCell.Well.Result.ConclusionList":
					{
						StringBuilder stringBuilder = new StringBuilder();
						foreach (Conclusion conclusion2 in chartData.WellCell.Well.Result.ConclusionList)
						{
							stringBuilder.Append(displayData ? ConvertConclusionToHtml(conclusion2) : (conclusion2.Content + " "));
						}
						if (!displayData && stringBuilder.Length > 0)
						{
							stringBuilder.Remove(stringBuilder.ToString().Length - 1, 1);
						}
						return stringBuilder.ToString();
					}
					case "SampleTargetItem.Result.ConclusionList":
					{
						StringBuilder stringBuilder = new StringBuilder();
						foreach (Conclusion conclusion3 in chartData.SampleTargetItem.Result.ConclusionList)
						{
							stringBuilder.Append(displayData ? ConvertConclusionToHtml(conclusion3) : (conclusion3.Content + " "));
						}
						if (!displayData && stringBuilder.Length > 0)
						{
							stringBuilder.Remove(stringBuilder.ToString().Length - 1, 1);
						}
						return stringBuilder.ToString();
					}
					}
				}
			}
			return string.Empty;
		}

		public void SaveSelectedDataToExcel(string file, bool selected = true)
		{
			ExcelData excelData = new ExcelData();
			ExcelSheetData excelSheetData = new ExcelSheetData();
			excelSheetData.Name = Utility.GetMessage("well_info_table");
			if (selected)
			{
				excelSheetData.Data = GetSelectedData();
				List<string> list = new List<string>();
				foreach (string item in excelSheetData.Data[0])
				{
					string text = item;
					list.Add(string.Empty);
				}
				excelSheetData.Data.Insert(0, list);
			}
			else
			{
				excelSheetData.Data = GetData(null, false, true);
			}
			excelData.SheetDataList.Add(excelSheetData);
			ExcelOperator.SaveToExcel(file, excelData);
		}

		public void SaveSelectedDataToCsv(string file)
		{
			CsvTxtOperator.SaveToCsv(file, GetSelectedData());
		}

		public void PrintWellInfo()
		{
			UltraGridPrintDocument ultraGridPrintDocument = new UltraGridPrintDocument();
			ultraGridPrintDocument.Grid = ultraGrid;
			ultraGridPrintDocument.Header.Appearance.FontData.SizeInPoints = 20f;
			ultraGridPrintDocument.Header.Margins.Bottom = 10;
			ultraGridPrintDocument.Header.TextCenter = Utility.GetMessage("experiment_report_title");
			ultraGridPrintDocument.Footer.TextRight = Utility.GetMessage("experiment_date") + Utility.GetMessage("Colon") + Experiment.Device.StartTime.ToShortDateString() + "     " + Utility.GetMessage("printing_date ") + Utility.GetMessage("Colon") + DateTime.Now.ToShortDateString() + "      Page <#> Of <##>";
			ultraGridPrintDocument.DefaultPageSettings.Landscape = true;
			UltraPrintPreviewDialog ultraPrintPreviewDialog = new UltraPrintPreviewDialog();
			ultraPrintPreviewDialog.Document = ultraGridPrintDocument;
			ultraPrintPreviewDialog.ShowDialog();
		}
	}
}
